diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ad73b4950..f8c90f2ad 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -30,6 +30,7 @@ Scripting improvements Interactive improvements ------------------------ +- :kbd:`Control-C` during command input no longer prints ``^C`` and a new prompt but merely clears the command line. This restores the behavior from version 2.2. To revert to the old behavior use ``bind \cc __fish_cancel_commandline`` (:issue:`10213`). - Command-specific tab completions may now offer results whose first character is a period. For example, it is now possible to tab-complete ``git add`` for files with leading periods. The default file completions hide these files, unless the token itself has a leading period (:issue:`3707`). - The :kbd:`Control-R` history search now uses glob syntax (:issue:`10131`). diff --git a/src/reader.rs b/src/reader.rs index 2c8b79ce0..f5a2c2071 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -72,7 +72,7 @@ use crate::io::IoChain; use crate::kill::{kill_add, kill_replace, kill_yank, kill_yank_rotate}; use crate::libc::MB_CUR_MAX; use crate::operation_context::{get_bg_context, OperationContext}; -use crate::output::{parse_color, Outputter}; +use crate::output::Outputter; use crate::pager::{PageRendering, Pager, SelectionMotion}; use crate::parse_constants::SourceRange; use crate::parse_constants::{ParseTreeFlags, ParserTestErrorBits}; @@ -2060,35 +2060,10 @@ impl ReaderData { if self.command_line.is_empty() { return; } - let outp = Outputter::stdoutput().get_mut(); - // Move cursor to the end of the line. - let end = self.command_line.len(); - self.update_buff_pos(EditableLineTag::Commandline, Some(end)); - self.autosuggestion.clear(); - // Repaint also changes the actual cursor position - if self.is_repaint_needed(None) { - self.layout_and_repaint(L!("cancel")); - } - - if let Some(fish_color_cancel) = self.vars().get(L!("fish_color_cancel")) { - outp.set_color( - parse_color(&fish_color_cancel, false), - parse_color(&fish_color_cancel, true), - ); - } - outp.write_wstr(L!("^C")); - outp.set_color(RgbColor::RESET, RgbColor::RESET); - - // We print a newline last so the prompt_sp hack doesn't get us. - outp.push(b'\n'); - - self.set_command_line_and_position( + self.push_edit( EditableLineTag::Commandline, - L!("").to_owned(), - 0, + Edit::new(0..self.command_line.len(), L!("").to_owned()), ); - self.screen - .reset_abandoning_line(usize::try_from(termsize_last().width).unwrap()); // Post fish_cancel. event::fire_generic(self.parser(), L!("fish_cancel").to_owned(), vec![]); diff --git a/tests/pexpects/cancel_event.py b/tests/pexpects/cancel_event.py index 474399d5c..af6e33410 100644 --- a/tests/pexpects/cancel_event.py +++ b/tests/pexpects/cancel_event.py @@ -27,13 +27,16 @@ if "CI" in os.environ: send("not executed") sleep(timeout) os.kill(sp.spawn.pid, signal.SIGINT) -sp.expect_str("not executed^C") -expect_prompt(increment=False) +sendline("echo marker") +sp.expect_str("marker") +expect_prompt() sendline("function cancelhandler --on-event fish_cancel ; echo yay cancelled ; end") expect_prompt() send("still not executed") sleep(timeout) os.kill(sp.spawn.pid, signal.SIGINT) -expect_str("still not executed^C") -expect_prompt("yay cancelled", increment=False) +expect_str("yay cancelled") +sendline("echo marker") +sp.expect_str("marker") +expect_prompt()