enhance the key_reader program

The original `key_reader` program was useful but didn't do much that `xxd`
or `od -tx1z` didn't do. Furthermore, it wasn't built and installed by
default. This change adds features that make it superior to those programs
for decoding interactive key presses and makes it a first-class citizen
like the `fish_indent` program that is always available.

Fixes #2991
This commit is contained in:
Kurtis Rader
2016-05-06 21:22:28 -07:00
parent 14d7b1a0fa
commit b055b8440c
8 changed files with 299 additions and 84 deletions

View File

@@ -14,6 +14,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <wchar.h>
#include <wctype.h>
@@ -28,9 +29,9 @@
#include "iothread.h"
#include "util.h"
// Time in milliseconds to wait for another byte to be available for reading
// after \x1b is read before assuming that escape key was pressed, and not an
// escape sequence.
/// Time in milliseconds to wait for another byte to be available for reading
/// after \x1b is read before assuming that escape key was pressed, and not an
/// escape sequence.
#define WAIT_ON_ESCAPE_DEFAULT 300
static int wait_on_escape_ms = WAIT_ON_ESCAPE_DEFAULT;
@@ -169,6 +170,9 @@ static wint_t readb() {
return arr[0];
}
// Directly set the input timeout.
void set_wait_on_escape_ms(int ms) { wait_on_escape_ms = ms; }
// Update the wait_on_escape_ms value in response to the fish_escape_delay_ms user variable being
// set.
void update_wait_on_escape_ms() {