diff --git a/libcommon/src/microvty.c b/libcommon/src/microvty.c index 9bb9887..ef7cbf3 100644 --- a/libcommon/src/microvty.c +++ b/libcommon/src/microvty.c @@ -84,6 +84,16 @@ static void cmd_buf_append(char c) g_cmds.buf[g_cmds.buf_idx++] = c; } +static bool cmd_buf_backspace(void) +{ + if (g_cmds.buf_idx > 0) { + g_cmds.buf_idx--; + g_cmds.buf[g_cmds.buf_idx] = 0; + return true; + } + return false; +} + /*! print the prompt to the console (stdout) */ void microvty_print_prompt(void) { @@ -125,6 +135,18 @@ static bool microvty_process_char(int c) cmd_buf_reset(); microvty_print_prompt(); return true; + } else if (c == '\b' || c == '\x7f') { + if (cmd_buf_backspace()) { + /* VT100 weirdness: Need to print backspace, space, backspace */ + printf("\b \b"); + } + } else if (c == 3) { /* Ctrl+C */ + printf("\r\n"); + microvty_print_prompt(); + return true; + } else if (c == '\t' || c == '\033') { + /* ignore control characters */ + return false; } else { /* print + append character */ putchar(c);