microvty: Implement backspace and ctrl+c support; ignnore TAB + ESC

This commit is contained in:
Harald Welte 2021-05-07 12:16:00 +02:00
parent 3cfd61baa7
commit b86a2daad1
1 changed files with 22 additions and 0 deletions

View File

@ -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);