diff mbox series

[1/1] cli: support bracketed paste

Message ID 20220411093955.28740-1-heinrich.schuchardt@canonical.com
State Accepted, archived
Commit 00fa8256b5c9b3ccbccbdfa8026bce2efd66d630
Delegated to: Tom Rini
Headers show
Series [1/1] cli: support bracketed paste | expand

Commit Message

Heinrich Schuchardt April 11, 2022, 9:39 a.m. UTC
Some consoles use CSI 200~ and CSI 201~ to bracket inserts. This leads
U-Boot to misinterpret the inserted string. Ignore these escape sequences.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 common/cli_readline.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/common/cli_readline.c b/common/cli_readline.c
index c7614a4c90..e86ee73faf 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -321,6 +321,7 @@  static int cread_line(const char *const prompt, char *buf, unsigned int *len,
 					act = ESC_CONVERTED;
 					break;	/* pass off to ^N handler */
 				case '1':
+				case '2':
 				case '3':
 				case '4':
 				case '7':
@@ -332,7 +333,8 @@  static int cread_line(const char *const prompt, char *buf, unsigned int *len,
 					break;
 				}
 			} else if (esc_len == 3) {
-				if (ichar == '~') {
+				switch (ichar) {
+				case '~':
 					switch (esc_save[2]) {
 					case '3':	/* Delete key */
 						ichar = CTL_CH('d');
@@ -349,9 +351,25 @@  static int cread_line(const char *const prompt, char *buf, unsigned int *len,
 						act = ESC_CONVERTED;
 						break;	/* pass to ^E handler */
 					}
+					break;
+				case '0':
+					if (esc_save[2] == '2')
+						act = ESC_SAVE;
+					break;
+				}
+			} else if (esc_len == 4) {
+				switch (ichar) {
+				case '0':
+				case '1':
+					act = ESC_SAVE;
+					break;		/* bracketed paste */
+				}
+			} else if (esc_len == 5) {
+				if (ichar == '~') {	/* bracketed paste */
+					ichar = 0;
+					act = ESC_CONVERTED;
 				}
 			}
-
 			switch (act) {
 			case ESC_SAVE:
 				esc_save[esc_len++] = ichar;