diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2016-02-04 13:56:06 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2016-02-04 13:56:49 -0800 |
commit | 25ad8866c97b242911b1e52298c8cfeed4530097 (patch) | |
tree | 8043d99a119ecef9bef288d9c77be9324898af80 /src | |
parent | 1d446b74ffb563ee18c298417b802458aad9ca84 (diff) | |
parent | 2646d51a0bb2551e1d53d164cea2a6a15be44b6e (diff) |
Merge change for lengthened and configurable escape key timeout
Diffstat (limited to 'src')
-rw-r--r-- | src/env.cpp | 6 | ||||
-rw-r--r-- | src/input_common.cpp | 64 | ||||
-rw-r--r-- | src/input_common.h | 3 |
3 files changed, 46 insertions, 27 deletions
diff --git a/src/env.cpp b/src/env.cpp index 3d7023db..527ed253 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -303,7 +303,7 @@ static void handle_locale() } -/** React to modifying hte given variable */ +/** React to modifying the given variable */ static void react_to_variable_change(const wcstring &key) { if (var_is_locale(key)) @@ -319,6 +319,10 @@ static void react_to_variable_change(const wcstring &key) { reader_react_to_color_change(); } + else if (key == L"fish_escape_delay_ms") + { + update_wait_on_escape_ms(); + } } /** diff --git a/src/input_common.cpp b/src/input_common.cpp index 24fde6e2..ebe95fce 100644 --- a/src/input_common.cpp +++ b/src/input_common.cpp @@ -28,12 +28,11 @@ Implementation file for the low level input library #include "env.h" #include "iothread.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. -*/ -#define WAIT_ON_ESCAPE 10 +// 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; /** Characters that have been read and returned by the sequence matching code */ static std::deque<wint_t> lookahead_list; @@ -77,6 +76,7 @@ static int (*interrupt_handler)(); void input_common_init(int (*ih)()) { interrupt_handler = ih; + update_wait_on_escape_ms(); } void input_common_destroy() @@ -212,36 +212,48 @@ static wint_t readb() return arr[0]; } +// 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() +{ + env_var_t escape_time_ms = env_get_string(L"fish_escape_delay_ms"); + if (escape_time_ms.missing_or_empty()) + { + wait_on_escape_ms = WAIT_ON_ESCAPE_DEFAULT; + return; + } + + wchar_t *endptr; + long tmp = wcstol(escape_time_ms.c_str(), &endptr, 10); + + if (*endptr != '\0' || tmp < 10 || tmp >= 5000) + { + fwprintf(stderr, L"ignoring fish_escape_delay_ms: value '%ls' " + "is not an integer or is < 10 or >= 5000 ms\n", + escape_time_ms.c_str()); + } + else + { + wait_on_escape_ms = (int)tmp; + } +} + + wchar_t input_common_readch(int timed) { if (! has_lookahead()) { if (timed) { - int count; fd_set fds; - struct timeval tm= - { - 0, - 1000 * WAIT_ON_ESCAPE - } - ; - FD_ZERO(&fds); FD_SET(0, &fds); - count = select(1, &fds, 0, 0, &tm); - - switch (count) + struct timeval tm = {wait_on_escape_ms / 1000, + 1000 * (wait_on_escape_ms % 1000)}; + int count = select(1, &fds, 0, 0, &tm); + if (count <= 0) { - case 0: - return WEOF; - - case -1: - return WEOF; - break; - default: - break; - + return WEOF; } } diff --git a/src/input_common.h b/src/input_common.h index 5ec34b39..72ccc073 100644 --- a/src/input_common.h +++ b/src/input_common.h @@ -35,6 +35,9 @@ void input_common_init(int (*ih)()); */ void input_common_destroy(); +// Adjust the escape timeout. +void update_wait_on_escape_ms(); + /** Function used by input_readch to read bytes from stdin until enough bytes have been read to convert them to a wchar_t. Conversion is |