Skip to content

Commit

Permalink
shell: Fix scrolling long commands in history
Browse files Browse the repository at this point in the history
This fixes scrolling long commands in command history in the shell

Signed-off-by: Rick Talbott <[email protected]>
  • Loading branch information
rtalbott-tmo authored and carlescufi committed Sep 13, 2023
1 parent 25d82dd commit 829b91a
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion subsys/shell/shell_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 829b91a

Please sign in to comment.