X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fserver%2Ftelnet_server.c;h=06a9c7a6c74a74597d2f5f5626f5a9f90eabc932;hb=e0010c3e6fe09d9d332b279e661858fc449c0645;hp=e33188b5e1e0f73c2a9c289e17ce12555050a186;hpb=3421b89c9809cbb39cd4bb030687a5c9fd65ded6;p=openocd.git diff --git a/src/server/telnet_server.c b/src/server/telnet_server.c index e33188b5e1..06a9c7a6c7 100644 --- a/src/server/telnet_server.c +++ b/src/server/telnet_server.c @@ -222,7 +222,6 @@ static int telnet_new_connection(struct connection *connection) telnet_connection->closed = 0; telnet_connection->line_size = 0; telnet_connection->line_cursor = 0; - telnet_connection->option_size = 0; telnet_connection->prompt = strdup("> "); telnet_connection->state = TELNET_STATE_DATA; @@ -304,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; @@ -483,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); }