From c0b39aaeb7fbe4d9ac59d5b5cfc1d4d17d905391 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 17 Feb 2021 11:04:22 -0800 Subject: [PATCH] Do not reset terminal color when donating term for running key bindings fish maintains two tty modes: one for itself and one for external commands. The external command mode is also used when executing fish-script key bindings, which was added in 5f16a299a728 (note that commit had the wrong issue, the correct issue is #2114). Prior to this fix, when switching to external modes, we would also reset the tty's foreground color. This bumped tty's timestamp, causing us to believe that the tty had been modified, and then repainting the prompt. If the prompt were multi-line, we would repaint the whole prompt starting from its second line, leaving a trailing line above it. It would be reasonable to save the tty timestamp after resetting the color, but given that using external modes for keybindings is new, it's better to instead not reset the color in this case. So migrate the color resetting to only when we run external commands. Fixes #7722 --- src/reader.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index ea5e806ca..a65cfb6b6 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -833,9 +833,7 @@ static void redirect_tty_after_sighup() { } /// Give up control of terminal. -static void term_donate(outputter_t &outp) { - outp.set_color(rgb_color_t::normal(), rgb_color_t::normal()); - +static void term_donate() { while (true) { if (tcsetattr(STDIN_FILENO, TCSANOW, &tty_modes_for_external_cmds) == -1) { if (errno == EIO) redirect_tty_output(); @@ -2376,7 +2374,8 @@ static eval_res_t reader_run_command(parser_t &parser, const wcstring &cmd) { outputter_t &outp = outputter_t::stdoutput(); reader_write_title(cmd, parser); - term_donate(outp); + outp.set_color(rgb_color_t::normal(), rgb_color_t::normal()); + term_donate(); gettimeofday(&time_before, nullptr); @@ -2798,8 +2797,8 @@ struct readline_loop_state_t { /// Run a sequence of commands from an input binding. void reader_data_t::run_input_command_scripts(const wcstring_list_t &cmds) { - // Need to donate/steal the tty - see #2214. - term_donate(outputter_t::stdoutput()); + // Need to donate/steal the tty - see #2114. + term_donate(); auto last_statuses = parser().get_last_statuses(); for (const wcstring &cmd : cmds) { parser().eval(cmd, io_chain_t{});