mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-30 23:51:15 -03:00
Make cancel-commandline actual bind function
This was always awkward as fish script, and had problems with interrupting the autoloading. Note that we still leave the old function intact to facilitate easier upgrading for now. Fixes #7145.
This commit is contained in:
@@ -1174,6 +1174,7 @@ static bool command_ends_paging(readline_cmd_t c, bool focused_on_search_field)
|
||||
case rl::history_token_search_forward:
|
||||
case rl::accept_autosuggestion:
|
||||
case rl::delete_or_exit:
|
||||
case rl::cancel_commandline:
|
||||
case rl::cancel: {
|
||||
// These commands always end paging.
|
||||
return true;
|
||||
@@ -2673,6 +2674,29 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
|
||||
mark_repaint_needed();
|
||||
break;
|
||||
}
|
||||
case rl::cancel_commandline: {
|
||||
if (command_line.size()) {
|
||||
outputter_t &outp = outputter_t::stdoutput();
|
||||
// Move cursor to the end of the line.
|
||||
update_buff_pos(&command_line, command_line.size());
|
||||
// Repaint also changes the actual cursor position
|
||||
repaint();
|
||||
|
||||
auto fish_color_cancel = vars.get(L"fish_color_cancel");
|
||||
if (fish_color_cancel) {
|
||||
outp.set_color(parse_color(*fish_color_cancel, false), parse_color(*fish_color_cancel, true));
|
||||
}
|
||||
outp.writestr(L"^C");
|
||||
outp.set_color(rgb_color_t::reset(), rgb_color_t::reset());
|
||||
|
||||
// We print a newline last so the prompt_sp hack doesn't get us.
|
||||
outp.push_back('\n');
|
||||
|
||||
set_command_line_and_position(&command_line, L"", 0);
|
||||
s_reset_abandoning_line(&screen, termsize_last().width - command_line.size());
|
||||
}
|
||||
break;
|
||||
}
|
||||
case rl::cancel: {
|
||||
// The only thing we can cancel right now is paging, which we handled up above.
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user