From 816b9a6953ef4bb76f0000ab173fa2ad808109b4 Mon Sep 17 00:00:00 2001 From: tsukimizake Date: Fri, 3 Jan 2025 00:48:35 +0900 Subject: [PATCH] stop the prompt from removing the last newline (#14590) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description I tried to setup a multiline prompt like this. スクリーンショット 2024-12-15 17 45 06 But when I set PROMT_COMMAND like this, ```nu $env.PROMPT_COMMAND = {|| $"(ansi reset)(ansi magenta)(date now | format date "%Y-%m-%dT%H:%M:%S%z")\n(pwd)\n" } ``` The result is like this, due to dropping `\n` and `\r` on `prompt_update.rs`. スクリーンショット 2024-12-15 17 54 21 Currently, adding two newlines can detour the drop. I think this drop newline makes little sense, so I removed it on this PR. If you don't like it, feel free to close it. # User-Facing Changes Trailing newline of PROMPT_COMMAND is not dropped anymore. # Tests + Formatting This is a subtle change just on prompt string, so I think particular test is not so necessary. # After Submitting As far as I read https://www.nushell.sh/book/coloring_and_theming.html#prompt-configuration-and-coloring , the behavior seems undocumented. --- crates/nu-cli/src/prompt_update.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/crates/nu-cli/src/prompt_update.rs b/crates/nu-cli/src/prompt_update.rs index c033475586..661b8c65f7 100644 --- a/crates/nu-cli/src/prompt_update.rs +++ b/crates/nu-cli/src/prompt_update.rs @@ -87,14 +87,6 @@ fn get_prompt_string( x.insert_str(0, "\x1b[0m") }; - // Just remove the very last newline. - if x.ends_with('\n') { - x.pop(); - } - - if x.ends_with('\r') { - x.pop(); - } x }); // Let's keep this for debugging purposes with nu --log-level warn