From 1008b729a7844890546206ac9c6ec26e3db4f764 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Tue, 28 Jun 2022 17:53:39 +0200 Subject: [PATCH] fish_job_summary: Format message better for multiline prompts This was supposed to be number of lines in the prompt minus 1, but string repeat added one. Also it triggered even in case of the stopped job message, which is already repainted differently. So we add it when we need to repaint ourselves. As a bonus add a newline before in that case so the message isn't awkwardly printed into the commandline. Fixes #9044. (cherry picked from commit 80fe0a7fcb42ab81903038c0d25c1f2e40aa1ed8) --- CHANGELOG.rst | 1 + share/functions/fish_job_summary.fish | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4956afdbc..7001acb8d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,7 @@ This release also fixes a number of problems identified in fish 3.5.0. - On terminals that emit a ``CSI u`` sequence for :kbd:`Shift-Space`, fish inserts a space instead of printing an error. (:issue:`9054`). - ``status fish-path`` on Linux-based platforms could print the path with a " (deleted)" suffix (such as ``/usr/bin/fish (deleted)``), which is now removed (:issue:`9019`). - Cancelling an initial command (from fish's ``--init-command`` option) with :kbd:`Control-C` no longer prevents configuration scripts from running (:issue:`9024`). +- The job summary contained extra blank lines if the prompt used multiple lines, which is now fixed (:issue:`9044`). -------------- diff --git a/share/functions/fish_job_summary.fish b/share/functions/fish_job_summary.fish index a552fabbc..004d593be 100644 --- a/share/functions/fish_job_summary.fish +++ b/share/functions/fish_job_summary.fish @@ -35,6 +35,11 @@ function fish_job_summary -a job_id is_foreground cmd_line signal_or_end_name si set cmd_line (string trim (string sub -l $truncated_len $cmd_line))$ellipsis end + if test $is_foreground -eq 0; and test $signal_or_end_name != STOPPED + # Add a newline *before* our message so we get the message after the commandline. + echo >&2 + end + switch $signal_or_end_name case STOPPED printf ( _ "fish: Job %s, '%s' has stopped\n" ) $job_id $cmd_line @@ -49,9 +54,11 @@ function fish_job_summary -a job_id is_foreground cmd_line signal_or_end_name si $job_id $cmd_line $signal_or_end_name $signal_desc end end >&2 - string repeat \n --count=(math (count (fish_prompt)) - 1) >&2 if test $is_foreground -eq 0; and test $signal_or_end_name != STOPPED + # We want one newline per line in the prompt after the first. + # To ensure that, don't let `string repeat` add a newline. See #9044. + string repeat -N \n --count=(math (count (fish_prompt)) - 1) >&2 commandline -f repaint end end