This change prevents misinterpreting an unknown ESC sequence's
commitecd3b62b8efea4d94fe8162eb0b50d223494efd0
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 21 May 2013 11:47:30 +0000 (21 14:47 +0300)
committerSlava Zanko <slavazanko@gmail.com>
Thu, 23 May 2013 08:42:02 +0000 (23 11:42 +0300)
treeafc545d600ca963be943dad77c71a012633a6de9
parent77cfaf03cb501819417179b53ad25ec68ee41a52
This change prevents misinterpreting an unknown ESC sequence's
tail as a garbage input. To reproduce, run "sleep 3" and
hold down Down_Arrow key until sleep runs.
With debugging log enabled, the following can be seen:

entered get_key_code(no_delay:0)
 c=tty_lowlevel_getch()=27
 push_char(27) !0
 c=xgetch_second()=91
 push_char(91) !0
 2 c=tty_lowlevel_getch()=66
 push_char(66)
 seq_buffer[0]:27   <---- the saved Down Arrow sequence "ESC [ B"
 seq_buffer[1]:91
 seq_buffer[2]:66
 seq_buffer[3]:0
pending_keys!=NULL. m=-1
d=*pending_keys++=27
d=ALT(*pending_keys++)=ALT(91)=8283
^^^^^^^^^^^^^^^^^^^^^^^ we misinterpret "ESC [ B" as "ESC ["
return correct_key_code(8283)
entered get_key_code(no_delay:0)
pending_keys!=NULL. m=-1
d=*pending_keys++=66
^^^^^^^^^^^^ we think user pressed "B"
return correct_key_code(66)

With this patch, no bogus "input" is generated.

Longer unknown sequences need an additional fix, coming next.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
lib/tty/key.c