diff mbox series

[v3,5/5] kdb: Tweak escape handling for vi users

Message ID 20191014154626.351-6-daniel.thompson@linaro.org
State Superseded
Headers show
Series kdb: Cleanup code to read user input and handle escape sequences | expand

Commit Message

Daniel Thompson Oct. 14, 2019, 3:46 p.m. UTC
Currently if sequences such as "\ehelp\r" are delivered to the console then
the h gets eaten by the escape handling code. Since pressing escape
becomes something of a nervous twitch for vi users (and that escape doesn't
have much effect at a shell prompt) it is more helpful to emit the 'h' than
the '\e'.

We don't simply choose to emit the final character for all escape sequences
since that will do odd things for unsupported escape sequences (in
other words we retain the existing behaviour once we see '\e[').

Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>

---
 kernel/debug/kdb/kdb_io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

-- 
2.21.0

Comments

Doug Anderson Oct. 17, 2019, 4:12 a.m. UTC | #1
Hi,

On Mon, Oct 14, 2019 at 8:46 AM Daniel Thompson
<daniel.thompson@linaro.org> wrote:
>

> Currently if sequences such as "\ehelp\r" are delivered to the console then

> the h gets eaten by the escape handling code. Since pressing escape

> becomes something of a nervous twitch for vi users (and that escape doesn't

> have much effect at a shell prompt) it is more helpful to emit the 'h' than

> the '\e'.

>

> We don't simply choose to emit the final character for all escape sequences

> since that will do odd things for unsupported escape sequences (in

> other words we retain the existing behaviour once we see '\e[').

>

> Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>

> ---

>  kernel/debug/kdb/kdb_io.c | 4 ++--

>  1 file changed, 2 insertions(+), 2 deletions(-)


Reviewed-by: Douglas Anderson <dianders@chromium.org>
diff mbox series

Patch

diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
index f9839566c7d6..5e71bb2596ed 100644
--- a/kernel/debug/kdb/kdb_io.c
+++ b/kernel/debug/kdb/kdb_io.c
@@ -161,8 +161,8 @@  char kdb_getchar(void)
 
 		*pbuf++ = key;
 		key = kdb_handle_escape(buf, pbuf - buf);
-		if (key < 0) /* no escape sequence; return first character */
-			return buf[0];
+		if (key < 0) /* no escape sequence; return best character */
+			return buf[pbuf - buf == 2 ? 1 : 0];
 		if (key > 0)
 			return key;
 	}