Skip to contentSkip to conversation

Reduce curses escdelay from 1s to 0.2s

PATCH In review Samuel Thibault 3 participants 3 messages Mar 3, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Reduce curses escdelay from 1s to 0.2s

By default, curses will only report single ESC key event after 1s delay, since ESC is also used for keypad escape sequences. This however makes users believe that ESC is not working. Reducing to 0.2s provides good enough user experience, while still allowing 200ms for keypad sequences to get in, which should be more than enough.

---
 ui/curses.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ui/curses.c +2 -1
index 6e0091c3b2..700315bc09 100644
@@ -231,7 +231,7 @@ static void curses_refresh(DisplayChangeListener *dcl)
         keycode = curses2keycode[chr];
         keycode_alt = 0;
 
-        /* alt key */
+        /* alt or esc key */
         if (keycode == 1) {
             int nextchr = getch();
 
@@ -361,6 +361,7 @@ static void curses_setup(void)
     initscr(); noecho(); intrflush(stdscr, FALSE);
     nodelay(stdscr, TRUE); nonl(); keypad(stdscr, TRUE);
     start_color(); raw(); scrollok(stdscr, FALSE);
+    set_escdelay(200);
 
     /* Make color pair to match color format (3bits bg:3bits fg) */
     for (i = 0; i < 64; i++) {
Signature · 1 line
2.20.1
#1 lore raw
Quoted 8 lines · Samuel Thibault

By default, curses will only report single ESC key event after 1s delay, since ESC is also used for keypad escape sequences. This however makes users
believe that ESC is not working. Reducing to 0.2s provides good enough user experience, while still allowing 200ms for keypad sequences to get in, which
should be more than enough.

How did you come up with this number? Still seems a bit long for the ESC ESC case where the user hits ESC twice in quick succession. Even back in the day, terminals would send the characters back to back at 1200 baud, which is 8ms per character. 32ms is 4x that, 32x 9600 baud rates. 25 or 50ms is suggested from these figures.

Warner

Quoted 30 lines
---
 ui/curses.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ui/curses.c +2 -2
index 6e0091c3b2..700315bc09 100644
@@ -231,7 +231,7 @@ static void curses_refresh(DisplayChangeListener *dcl)
         keycode = curses2keycode[chr];
         keycode_alt = 0;
 
-        /* alt key */
+        /* alt or esc key */
         if (keycode == 1) {
             int nextchr = getch();
 
@@ -361,6 +361,7 @@ static void curses_setup(void)
     initscr(); noecho(); intrflush(stdscr, FALSE);
     nodelay(stdscr, TRUE); nonl(); keypad(stdscr, TRUE);
     start_color(); raw(); scrollok(stdscr, FALSE);
+    set_escdelay(200);
 
     /* Make color pair to match color format (3bits bg:3bits fg) */
     for (i = 0; i < 64; i++) {
--

2.20.1

#2 lore raw

Warner Losh, le dim. 03 mars 2019 10:11:52 -0700, a ecrit:

Quoted 11 lines

On Sun, Mar 3, 2019, 12:45 AM Samuel Thibault <[1][email protected]> wrote:

By default, curses will only report single ESC key event after 1s delay, since ESC is also used for keypad escape sequences. This however makes users
believe that ESC is not working. Reducing to 0.2s provides good enough user experience, while still allowing 200ms for keypad sequences to get in, which
should be more than enough.

Quoted 1 line

How did you come up with this number?

Since the default was very long, I chose a value that felt fast enough for the user.

Quoted 2 lines

Still seems a bit long for the ESC ESC case where the user hits ESC twice in quick succession.

Right, there might be such double-press.

Quoted 3 lines

Even back in the day, terminals would send the characters back to back at 1200 baud, which is 8ms per character. 32ms is 4x that, 32x 9600 baud rates. 25 or 50ms is suggested from these figures.

Alright, let's try 25 then.

Samuel