From 7bdeffb5a6eae17c4ac40f86898eb2ecf5d84222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Thu, 5 Jun 2025 12:44:43 +0200 Subject: [PATCH] shell: fix margin handling after newlines in formatted help text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines following newlines in shell help text were not properly indented. For example, in "abc def\ndef ghi\njkl mno", the lines "def ghi" and "jkl mno" would appear without the expected left margin. The issue was that after processing a newline and setting proper cursor position, the function would fall through to z_shell_raw_fprintf() which Signed-off-by: Benjamin Cabé --- subsys/shell/shell_help.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/subsys/shell/shell_help.c b/subsys/shell/shell_help.c index 95419dba101..893cb208d84 100644 --- a/subsys/shell/shell_help.c +++ b/subsys/shell/shell_help.c @@ -38,6 +38,7 @@ static void formatted_text_print(const struct shell *sh, const char *str, while (true) { size_t idx = 0; + bool newline_found = false; length = z_shell_strlen(str) - offset; @@ -51,10 +52,16 @@ static void formatted_text_print(const struct shell *sh, const char *str, z_cursor_next_line_move(sh); z_shell_op_cursor_horiz_move(sh, terminal_offset); + newline_found = true; break; } } + /* If we found a newline, continue processing the remaining text */ + if (newline_found) { + continue; + } + /* String will fit in one line. */ z_shell_raw_fprintf(sh->fprintf_ctx, str + offset);