diff --git a/src/exec.rs b/src/exec.rs index 46625d0a9..c656de1a6 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -1320,6 +1320,7 @@ fn exec_process_in_job( piped_output_needs_buffering, ), ProcessType::external => { + parser.libdata_mut().exec_external_count += 1; exec_external_command(parser, j, p, &process_net_io_chain)?; // It's possible (though unlikely) that this is a background process which recycled a // pid from another, previous background process. Forget any such old process. diff --git a/src/parser.rs b/src/parser.rs index e48a55f87..57423e596 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -236,6 +236,9 @@ pub struct LibraryData { /// A counter incremented every time a command executes. pub exec_count: u64, + /// A counter incremented every time an external command executes. + pub exec_external_count: u64, + /// A counter incremented every time a command produces a $status. pub status_count: u64, diff --git a/src/reader.rs b/src/reader.rs index 7cb30af45..a9b8e0130 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1996,8 +1996,14 @@ impl<'a> Reader<'a> { fn eval_bind_cmd(&mut self, cmd: &wstr) { let last_statuses = self.parser.vars().get_last_statuses(); + let prev_exec_external_count = self.parser.libdata().exec_external_count; self.parser.eval(cmd, &IoChain::new()); self.parser.set_last_statuses(last_statuses); + if self.parser.libdata().exec_external_count != prev_exec_external_count + && self.data.left_prompt_buff.contains('\n') + { + self.save_screen_state(); + } } /// Run a sequence of commands from an input binding. @@ -2862,7 +2868,6 @@ impl<'a> Reader<'a> { self.force_exec_prompt_and_repaint = true; self.input_data .queue_char(CharEvent::from_readline(ReadlineCmd::Repaint)); - self.save_screen_state(); return; } @@ -2885,7 +2890,6 @@ impl<'a> Reader<'a> { self.force_exec_prompt_and_repaint = true; self.input_data .queue_char(CharEvent::from_readline(ReadlineCmd::Repaint)); - self.save_screen_state(); return; } diff --git a/tests/checks/tmux-multiline-prompt.fish b/tests/checks/tmux-multiline-prompt.fish index cbdfa7445..65b9596a4 100644 --- a/tests/checks/tmux-multiline-prompt.fish +++ b/tests/checks/tmux-multiline-prompt.fish @@ -1,5 +1,6 @@ #RUN: %fish %s #REQUIRES: command -v tmux && ! tmux -V | grep -qE '^tmux (next-3.4|3\.[0123][a-z]*($|[.-]))' +#REQUIRES: command -v less isolated-tmux-start @@ -45,3 +46,16 @@ isolated-tmux capture-pane -p | tail -n 5 # CHECK: prompt-line-2> # CHECK: # CHECK: + +# Test repainint after running an external program that uses the alternate screen. +isolated-tmux send-keys 'bind ctrl-r "echo | less +q; commandline \'echo Hello World\'"' Enter C-l \ +isolated-tmux send-keys C-r +tmux-sleep +isolated-tmux send-keys Enter +tmux-sleep +isolated-tmux capture-pane -p +# CHECK: prompt-line-1 +# CHECK: prompt-line-2> echo Hello World +# CHECK: Hello World +# CHECK: prompt-line-1 +# CHECK: prompt-line-2>