Skip to content

Commit 7bdeffb

Browse files
committed
shell: fix margin handling after newlines in formatted help text
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é <benjamin@zephyrproject.org>
1 parent 75bfd79 commit 7bdeffb

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

subsys/shell/shell_help.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static void formatted_text_print(const struct shell *sh, const char *str,
3838

3939
while (true) {
4040
size_t idx = 0;
41+
bool newline_found = false;
4142

4243
length = z_shell_strlen(str) - offset;
4344

@@ -51,10 +52,16 @@ static void formatted_text_print(const struct shell *sh, const char *str,
5152
z_cursor_next_line_move(sh);
5253
z_shell_op_cursor_horiz_move(sh,
5354
terminal_offset);
55+
newline_found = true;
5456
break;
5557
}
5658
}
5759

60+
/* If we found a newline, continue processing the remaining text */
61+
if (newline_found) {
62+
continue;
63+
}
64+
5865
/* String will fit in one line. */
5966
z_shell_raw_fprintf(sh->fprintf_ctx, str + offset);
6067

0 commit comments

Comments
 (0)