Skip to content
Permalink
Browse files

shell: add Ctrl+N and Ctrl+P meta-keys

Ctrl+N - moves in history to next entry
Ctrl+P - moves in history to previous entry

Behavior of those meta-keys is the same as in bash and emacs, which
makes Zephyr shell even more familiar to play with.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
  • Loading branch information...
mniestroj authored and nashif committed Jun 22, 2019
1 parent 74818bc commit 0d6fabe6c350376168d90762c0e0a7a931c15be3
Showing with 12 additions and 2 deletions.
  1. +8 −0 subsys/shell/shell.c
  2. +2 −2 subsys/shell/shell_cmds.c
  3. +2 −0 subsys/shell/shell_vt100.h
@@ -801,6 +801,14 @@ static void ctrl_metakeys_handle(const struct shell *shell, char data)
shell_print_prompt_and_cmd(shell);
break;

case SHELL_VT100_ASCII_CTRL_N: /* CTRL + N */
history_handle(shell, false);
break;

case SHELL_VT100_ASCII_CTRL_P: /* CTRL + P */
history_handle(shell, true);
break;

case SHELL_VT100_ASCII_CTRL_U: /* CTRL + U */
shell_op_cursor_home_move(shell);
cmd_buffer_clear(shell);
@@ -288,8 +288,8 @@ static int cmd_help(const struct shell *shell, size_t argc, char **argv)
shell_print(shell,
"Shell supports following meta-keys:\n"
"Ctrl+a, Ctrl+b, Ctrl+c, Ctrl+d, Ctrl+e, Ctrl+f, Ctrl+k,"
" Ctrl+l, Ctrl+u, Ctrl+w\nAlt+b, Alt+f.\nPlease refer to"
" shell documentation for more details.");
" Ctrl+l, Ctrl+n, Ctrl+p, Ctrl+u, Ctrl+w\nAlt+b, Alt+f.\n"
"Please refer to shell documentation for more details.");
#endif

return 0;
@@ -18,6 +18,8 @@
#define SHELL_VT100_ASCII_CTRL_F (0x06)
#define SHELL_VT100_ASCII_CTRL_K (0x0B)
#define SHELL_VT100_ASCII_CTRL_L (0x0C)
#define SHELL_VT100_ASCII_CTRL_N (0x0E)
#define SHELL_VT100_ASCII_CTRL_P (0x10)
#define SHELL_VT100_ASCII_CTRL_U (0x15)
#define SHELL_VT100_ASCII_CTRL_W (0x17)
#define SHELL_VT100_ASCII_ALT_B (0x62)

0 comments on commit 0d6fabe

Please sign in to comment.
You can’t perform that action at this time.