parent
0c1b27cfa7
commit
b370f91025
|
@ -1068,7 +1068,10 @@ const CommandDesc prompt_cmd = {
|
|||
nullptr,
|
||||
"prompt <prompt> <register> <command>: prompt the use to enter a text string "
|
||||
"stores it in <register> and then executes <command>",
|
||||
ParameterDesc{ SwitchMap{}, ParameterDesc::Flags::None, 3, 3 },
|
||||
ParameterDesc{
|
||||
SwitchMap{ { "init", { true, "set initial prompt content" } } },
|
||||
ParameterDesc::Flags::None, 3, 3
|
||||
},
|
||||
CommandFlags::None,
|
||||
CommandCompleter{},
|
||||
[](const ParametersParser& params, Context& context)
|
||||
|
@ -1078,8 +1081,12 @@ const CommandDesc prompt_cmd = {
|
|||
const char reg = params[1][0];
|
||||
const String& command = params[2];
|
||||
|
||||
String initstr;
|
||||
if (params.has_option("init"))
|
||||
initstr = params.option_value("init");
|
||||
|
||||
context.input_handler().prompt(
|
||||
params[0], get_color("Prompt"), Completer{},
|
||||
params[0], std::move(initstr), get_color("Prompt"), Completer{},
|
||||
[=](const String& str, PromptEvent event, Context& context)
|
||||
{
|
||||
if (event != PromptEvent::Validate)
|
||||
|
|
|
@ -353,13 +353,15 @@ class Prompt : public InputMode
|
|||
{
|
||||
public:
|
||||
Prompt(InputHandler& input_handler, const String& prompt,
|
||||
ColorPair colors, Completer completer, PromptCallback callback)
|
||||
String initstr, ColorPair colors, Completer completer,
|
||||
PromptCallback callback)
|
||||
: InputMode(input_handler), m_prompt(prompt), m_prompt_colors(colors),
|
||||
m_completer(completer), m_callback(callback)
|
||||
{
|
||||
m_history_it = ms_history[m_prompt].end();
|
||||
if (context().options()["autoshowcompl"].get<bool>())
|
||||
refresh_completions(CompletionFlags::Fast);
|
||||
m_line_editor.reset(std::move(initstr));
|
||||
display();
|
||||
}
|
||||
|
||||
|
@ -1259,11 +1261,13 @@ void InputHandler::repeat_last_insert()
|
|||
kak_assert(dynamic_cast<InputModes::Normal*>(m_mode.get()) != nullptr);
|
||||
}
|
||||
|
||||
void InputHandler::prompt(const String& prompt, ColorPair prompt_colors,
|
||||
Completer completer, PromptCallback callback)
|
||||
void InputHandler::prompt(const String& prompt, String initstr,
|
||||
ColorPair prompt_colors, Completer completer,
|
||||
PromptCallback callback)
|
||||
{
|
||||
change_input_mode(new InputModes::Prompt(*this, prompt, prompt_colors,
|
||||
completer, callback));
|
||||
change_input_mode(new InputModes::Prompt(*this, prompt, initstr,
|
||||
prompt_colors, completer,
|
||||
callback));
|
||||
}
|
||||
|
||||
void InputHandler::set_prompt_colors(ColorPair prompt_colors)
|
||||
|
|
|
@ -47,8 +47,9 @@ public:
|
|||
// abort or validation with corresponding PromptEvent value
|
||||
// returns to normal mode after validation if callback does
|
||||
// not change the mode itself
|
||||
void prompt(const String& prompt, ColorPair prompt_colors,
|
||||
Completer completer, PromptCallback callback);
|
||||
void prompt(const String& prompt, String initstr,
|
||||
ColorPair prompt_colors, Completer completer,
|
||||
PromptCallback callback);
|
||||
void set_prompt_colors(ColorPair prompt_colors);
|
||||
|
||||
// enter menu mode, callback is called on each selection change,
|
||||
|
|
|
@ -426,7 +426,7 @@ void for_each_char(Context& context, int)
|
|||
void command(Context& context, int)
|
||||
{
|
||||
context.input_handler().prompt(
|
||||
":", get_color("Prompt"),
|
||||
":", "", get_color("Prompt"),
|
||||
std::bind(&CommandManager::complete, &CommandManager::instance(), _1, _2, _3, _4),
|
||||
[](const String& cmdline, PromptEvent event, Context& context) {
|
||||
if (context.has_ui())
|
||||
|
@ -451,7 +451,7 @@ template<InsertMode mode>
|
|||
void pipe(Context& context, int)
|
||||
{
|
||||
const char* prompt = mode == InsertMode::Replace ? "pipe:" : "pipe (ins):";
|
||||
context.input_handler().prompt(prompt, get_color("Prompt"), shell_complete,
|
||||
context.input_handler().prompt(prompt, "", get_color("Prompt"), shell_complete,
|
||||
[](const String& cmdline, PromptEvent event, Context& context)
|
||||
{
|
||||
if (event != PromptEvent::Validate)
|
||||
|
@ -589,7 +589,7 @@ template<typename T>
|
|||
void regex_prompt(Context& context, const String prompt, T func)
|
||||
{
|
||||
DynamicSelectionList selections{context.buffer(), context.selections()};
|
||||
context.input_handler().prompt(prompt, get_color("Prompt"), complete_nothing,
|
||||
context.input_handler().prompt(prompt, "", get_color("Prompt"), complete_nothing,
|
||||
[=](const String& str, PromptEvent event, Context& context) {
|
||||
try
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user