summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorManos Pitsidianakis <manos.pitsidianakis@linaro.org>2024-06-13 11:06:13 +0300
committerPhilippe Mathieu-Daudé <philmd@linaro.org>2024-06-19 12:42:03 +0200
commite1e55d346a2f648f05d36bed7edcd3910f516f1d (patch)
tree0a08f2e4c3d83afca823bd130faf91846b2aa928
parent96c99e38312c517115a9c4f9e9d409059818e56d (diff)
downloadfocaccia-qemu-e1e55d346a2f648f05d36bed7edcd3910f516f1d.tar.gz
focaccia-qemu-e1e55d346a2f648f05d36bed7edcd3910f516f1d.zip
util/readline: Add C-u shortcut
Add support for the unix-line-discard readline action, which erases from
the cursor position up to the beginning of the line. The default
binding, C-u, was chosen.

This is useful to quickly erase command input while working on the
monitor interface.

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <6772067e1c0d4b1c5310e5446e9e3e1c6b3b5bc0.1718265822.git.manos.pitsidianakis@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
-rw-r--r--util/readline.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/util/readline.c b/util/readline.c
index 0b627d62ad..0f19674f52 100644
--- a/util/readline.c
+++ b/util/readline.c
@@ -271,6 +271,14 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
     rs->hist_entry = -1;
 }
 
+static void readline_kill_line(ReadLineState *rs)
+{
+    while (rs->cmd_buf_index > 0) {
+        readline_backward_char(rs);
+        readline_delete_char(rs);
+    }
+}
+
 /* completion support */
 
 void readline_add_completion(ReadLineState *rs, const char *str)
@@ -426,6 +434,10 @@ void readline_handle_byte(ReadLineState *rs, int ch)
             /* ^P Prev line in history */
             readline_up_char(rs);
             break;
+        case 21:
+            /* ^U Kill backward from point to the beginning of the line. */
+            readline_kill_line(rs);
+            break;
         case 23:
             /* ^W */
             readline_backword(rs);