server/telnet: Handle Ctrl+K

Handle Ctrl+K shortcut which clears the line from the cursor position
to the end of line.

Change-Id: I2ecff5284473cef7c11cf9cb7e1c0c97d55f6c1c
Signed-off-by: Brian Brooks <brooks.brian@gmail.com>
Reviewed-on: http://openocd.zylin.com/5868
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
Reviewed-by: Marc Schink <dev@zapb.de>
This commit is contained in:
Brian Brooks 2020-10-18 08:37:09 -05:00 committed by Antonio Borneo
parent 0d3a67b23f
commit 9e2a0effb2
1 changed files with 11 additions and 1 deletions

View File

@ -538,7 +538,17 @@ static int telnet_input(struct connection *connection)
telnet_move_cursor(connection, 0);
else if (*buf_p == CTRL('E'))
telnet_move_cursor(connection, t_con->line_size);
else
else if (*buf_p == CTRL('K')) { /* kill line to end */
if (t_con->line_cursor < t_con->line_size) {
/* overwrite with space, until end of line, move back */
for (size_t i = t_con->line_cursor; i < t_con->line_size; i++)
telnet_write(connection, " ", 1);
for (size_t i = t_con->line_cursor; i < t_con->line_size; i++)
telnet_write(connection, "\b", 1);
t_con->line[t_con->line_cursor] = '\0';
t_con->line_size = t_con->line_cursor;
}
} else
LOG_DEBUG("unhandled nonprintable: %2.2x", *buf_p);
}
}