Fix shell context capture that was accessing dead parameters
Fixes #1156
This commit is contained in:
parent
bbbb513990
commit
8a62ec12af
|
@ -1686,6 +1686,17 @@ const CommandDesc eval_string_cmd = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CapturedShellContext
|
||||||
|
{
|
||||||
|
explicit CapturedShellContext(const ShellContext& sc)
|
||||||
|
: params{sc.params.begin(), sc.params.end()}, env_vars{sc.env_vars} {}
|
||||||
|
|
||||||
|
Vector<String> params;
|
||||||
|
EnvVarMap env_vars;
|
||||||
|
|
||||||
|
operator ShellContext() const { return { params, env_vars }; }
|
||||||
|
};
|
||||||
|
|
||||||
const CommandDesc prompt_cmd = {
|
const CommandDesc prompt_cmd = {
|
||||||
"prompt",
|
"prompt",
|
||||||
nullptr,
|
nullptr,
|
||||||
|
@ -1735,8 +1746,7 @@ const CommandDesc prompt_cmd = {
|
||||||
const auto flags = parser.get_switch("password") ?
|
const auto flags = parser.get_switch("password") ?
|
||||||
PromptFlags::Password : PromptFlags::None;
|
PromptFlags::Password : PromptFlags::None;
|
||||||
|
|
||||||
// const cast so that lambda capute is mutable
|
CapturedShellContext sc{shell_context};
|
||||||
ShellContext& sc = const_cast<ShellContext&>(shell_context);
|
|
||||||
context.input_handler().prompt(
|
context.input_handler().prompt(
|
||||||
parser[0], initstr.str(), get_face("Prompt"),
|
parser[0], initstr.str(), get_face("Prompt"),
|
||||||
flags, std::move(completer),
|
flags, std::move(completer),
|
||||||
|
@ -1803,14 +1813,15 @@ const CommandDesc menu_cmd = {
|
||||||
select_cmds.push_back(parser[i+2]);
|
select_cmds.push_back(parser[i+2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CapturedShellContext sc{shell_context};
|
||||||
context.input_handler().menu(std::move(choices),
|
context.input_handler().menu(std::move(choices),
|
||||||
[=](int choice, MenuEvent event, Context& context) {
|
[=](int choice, MenuEvent event, Context& context) {
|
||||||
ScopedSetBool disable_history{context.history_disabled()};
|
ScopedSetBool disable_history{context.history_disabled()};
|
||||||
|
|
||||||
if (event == MenuEvent::Validate and choice >= 0 and choice < commands.size())
|
if (event == MenuEvent::Validate and choice >= 0 and choice < commands.size())
|
||||||
CommandManager::instance().execute(commands[choice], context, shell_context);
|
CommandManager::instance().execute(commands[choice], context, sc);
|
||||||
if (event == MenuEvent::Select and choice >= 0 and choice < select_cmds.size())
|
if (event == MenuEvent::Select and choice >= 0 and choice < select_cmds.size())
|
||||||
CommandManager::instance().execute(select_cmds[choice], context, shell_context);
|
CommandManager::instance().execute(select_cmds[choice], context, sc);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1828,8 +1839,7 @@ const CommandDesc on_key_cmd = {
|
||||||
{
|
{
|
||||||
String command = parser[0];
|
String command = parser[0];
|
||||||
|
|
||||||
// const cast so that the lambda capute is mutable
|
CapturedShellContext sc{shell_context};
|
||||||
ShellContext& sc = const_cast<ShellContext&>(shell_context);
|
|
||||||
context.input_handler().on_next_key(
|
context.input_handler().on_next_key(
|
||||||
KeymapMode::None, [=](Key key, Context& context) mutable {
|
KeymapMode::None, [=](Key key, Context& context) mutable {
|
||||||
sc.env_vars["key"] = key_to_str(key);
|
sc.env_vars["key"] = key_to_str(key);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user