]> git.sur5r.net Git - openocd/commitdiff
server/telnet: Handle Ctrl+A and Ctrl+E
authorMarc Schink <openocd-dev@marcschink.de>
Sun, 4 Oct 2015 18:21:00 +0000 (20:21 +0200)
committerPaul Fertser <fercerpav@gmail.com>
Sat, 13 Jan 2018 09:41:26 +0000 (09:41 +0000)
Handle the Ctrl+A and Ctrl+E shortcuts which move the cursor to the
beginning and end of the command line, respectively.

Change-Id: I89fa5fd3c5edeb08a3f9320fda766f72ce9d7f64
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/3415
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
src/server/telnet_server.c

index 7507afea8d688613eeadff39940e22ba743cc911..06a9c7a6c74a74597d2f5f5626f5a9f90eabc932 100644 (file)
@@ -303,6 +303,30 @@ static void telnet_history_down(struct connection *connection)
        telnet_history_go(connection, next_history);
 }
 
+static void telnet_move_cursor(struct connection *connection, size_t pos)
+{
+       struct telnet_connection *tc;
+       size_t tmp;
+
+       tc = connection->priv;
+
+       if (pos < tc->line_cursor) {
+               tmp = tc->line_cursor - pos;
+
+               for (size_t i = 0; i < tmp; i += 16)
+                       telnet_write(connection, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b",
+                               MIN(tmp - i, 16));
+       } else {
+               tmp = pos - tc->line_cursor;
+
+               for (size_t i = 0; i < tmp; i += 16)
+                       telnet_write(connection, tc->line + tc->line_cursor + i,
+                               MIN(tmp - i, 16));
+       }
+
+       tc->line_cursor = pos;
+}
+
 static int telnet_input(struct connection *connection)
 {
        int bytes_read;
@@ -482,6 +506,10 @@ static int telnet_input(struct connection *connection)
                                                        telnet_history_up(connection);
                                                else if (*buf_p == CTRL('N'))           /* cursor down */
                                                        telnet_history_down(connection);
+                                               else if (*buf_p == CTRL('A'))
+                                                       telnet_move_cursor(connection, 0);
+                                               else if (*buf_p == CTRL('E'))
+                                                       telnet_move_cursor(connection, t_con->line_size);
                                                else
                                                        LOG_DEBUG("unhandled nonprintable: %2.2x", *buf_p);
                                        }