less: add a bit more robustness in keyboard reading code
This commit is contained in:
parent
0e2c9fb4e0
commit
46340e398e
@ -699,10 +699,11 @@ static int less_getch(void)
|
|||||||
char input[16];
|
char input[16];
|
||||||
unsigned i;
|
unsigned i;
|
||||||
again:
|
again:
|
||||||
|
memset(input, 0, sizeof(input));
|
||||||
getch_nowait(input, sizeof(input));
|
getch_nowait(input, sizeof(input));
|
||||||
|
|
||||||
/* Detect escape sequences (i.e. arrow keys) and handle
|
/* Detect escape sequences (i.e. arrow keys) and handle
|
||||||
* them accordingly */
|
* them accordingly */
|
||||||
|
|
||||||
if (input[0] == '\033' && input[1] == '[') {
|
if (input[0] == '\033' && input[1] == '[') {
|
||||||
set_tty_cooked();
|
set_tty_cooked();
|
||||||
i = input[2] - REAL_KEY_UP;
|
i = input[2] - REAL_KEY_UP;
|
||||||
@ -740,6 +741,7 @@ static char* less_gets(int sz)
|
|||||||
* but it is needed. Is it because of stdio? */
|
* but it is needed. Is it because of stdio? */
|
||||||
tcsetattr(kbd_fd, TCSANOW, &term_less);
|
tcsetattr(kbd_fd, TCSANOW, &term_less);
|
||||||
|
|
||||||
|
c = '\0';
|
||||||
read(kbd_fd, &c, 1);
|
read(kbd_fd, &c, 1);
|
||||||
if (c == 0x0d)
|
if (c == 0x0d)
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user