server/telnet: support 'CTRL+C'
authorTarek BOCHKATI <tarek.bouchkati@gmail.com>
Tue, 17 Aug 2021 12:29:56 +0000 (13:29 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Mon, 30 Aug 2021 13:53:48 +0000 (13:53 +0000)
like in terminal 'CTRL+C':
 - keeps the line content so the user can refer to it (like copy/paste)
 - marks the line with '^C', as hint that the command was not executed
 - permit the user to write a new command

Change-Id: Ib784c827d64fdc439a35db461d8387a62d3bfbbf
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6439
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
src/server/telnet_server.c

index 253591ec948823e71424883b94fe8ebbca926a56..f7b3f6449bbfda33c3daa894a1ad963f7ccdb052 100644 (file)
@@ -718,6 +718,13 @@ static int telnet_input(struct connection *connection)
                                                                t_con->line_cursor--;
                                                        }
                                                        t_con->state = TELNET_STATE_DATA;
+                                               } else if (*buf_p == CTRL('C')) {       /* interrupt */
+                                                       /* print '^C' at line end, and display a new command prompt */
+                                                       telnet_move_cursor(connection, t_con->line_size);
+                                                       telnet_write(connection, "^C\n\r", 4);
+                                                       t_con->line_cursor = 0;
+                                                       t_con->line_size = 0;
+                                                       telnet_prompt(connection);
                                                } else if (*buf_p == CTRL('F')) {       /* cursor right */
                                                        if (t_con->line_cursor < t_con->line_size)
                                                                telnet_write(connection, t_con->line + t_con->line_cursor++, 1);