From 829b91ab2f96e1b2455ddd5cc5e281be0f561b88 Mon Sep 17 00:00:00 2001 From: Rick Talbott Date: Fri, 23 Jun 2023 14:33:08 -0600 Subject: [PATCH] shell: Fix scrolling long commands in history This fixes scrolling long commands in command history in the shell Signed-off-by: Rick Talbott --- subsys/shell/shell_ops.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/subsys/shell/shell_ops.c b/subsys/shell/shell_ops.c index db68c62155..7b9af71e41 100644 --- a/subsys/shell/shell_ops.c +++ b/subsys/shell/shell_ops.c @@ -367,7 +367,29 @@ static void print_prompt(const struct shell *sh) void z_shell_print_cmd(const struct shell *sh) { - z_shell_raw_fprintf(sh->fprintf_ctx, "%s", sh->ctx->cmd_buff); + int beg_offset = 0; + int end_offset = 0; + int cmd_width = z_shell_strlen(sh->ctx->cmd_buff); + int adjust = sh->ctx->vt100_ctx.cons.name_len; + char ch; + + while (cmd_width > sh->ctx->vt100_ctx.cons.terminal_wid - adjust) { + end_offset += sh->ctx->vt100_ctx.cons.terminal_wid - adjust; + ch = sh->ctx->cmd_buff[end_offset]; + sh->ctx->cmd_buff[end_offset] = '\0'; + + z_shell_raw_fprintf(sh->fprintf_ctx, "%s\n", + &sh->ctx->cmd_buff[beg_offset]); + + sh->ctx->cmd_buff[end_offset] = ch; + cmd_width -= (sh->ctx->vt100_ctx.cons.terminal_wid - adjust); + beg_offset = end_offset; + adjust = 0; + } + if (cmd_width > 0) { + z_shell_raw_fprintf(sh->fprintf_ctx, "%s", + &sh->ctx->cmd_buff[beg_offset]); + } } void z_shell_print_prompt_and_cmd(const struct shell *sh)