From ae6b359109c2254ffa7e0add797c077c21780079 Mon Sep 17 00:00:00 2001 From: Naqua Darazaki Date: Tue, 2 Jul 2024 13:54:11 +0200 Subject: [PATCH] Add ctrl + left/right arrow support to the REPL Ctrl + left/right arrow would simply input "5D"/"5C" into the REPL which was useless and confusing With this change, it instead goes to the previous/next word which is usually expected in readline-like interfaces --- src/mainclient/shell.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mainclient/shell.c b/src/mainclient/shell.c index 696fb352..ec93df69 100644 --- a/src/mainclient/shell.c +++ b/src/mainclient/shell.c @@ -867,7 +867,7 @@ static int line() { if (write_console((char *) gbl_prompt, gbl_plen) == -1) return -1; for (;;) { char c; - char seq[3]; + char seq[5]; int rc; do { @@ -991,6 +991,20 @@ static int line() { default: break; } + } else if (seq[2] == ';') { + if (read_console(seq + 3, 2) == -1) break; + if (seq[3] == '5') { + switch (seq[4]) { + case 'C': /* ctrl-right */ + krightw(); + break; + case 'D': /* ctrl-left */ + kleftw(); + break; + default: + break; + } + } } } else if (seq[0] == 'O') { if (read_console(seq + 1, 1) == -1) break;