aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/input_common.cpp
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-01-14 21:46:53 -0800
committerGravatar Kurtis Rader <krader@skepticism.us>2016-01-17 17:45:30 -0800
commit4b9fece9f48615f2e8068054c60763e844415a7c (patch)
tree794abe80d918138297592c13054c75a4dcb4db20 /src/input_common.cpp
parent6969cfab3dc20de9f757b94b8832b504ed1fdd40 (diff)
allow configuring the escape delay timeout
Introduce a "fish_escape_delay_ms" variable to allow the user to configure the delay used when seeing a bare escape before assuming no other characters will be received that might match a bound character sequence. This is primarily useful for vi mode so that a bare escape character (i.e., keystroke) can switch to vi "insert" to "normal" mode in a timely fashion.
Diffstat (limited to 'src/input_common.cpp')
-rw-r--r--src/input_common.cpp59
1 files changed, 37 insertions, 22 deletions
diff --git a/src/input_common.cpp b/src/input_common.cpp
index cda4ca11..291a37a7 100644
--- a/src/input_common.cpp
+++ b/src/input_common.cpp
@@ -33,9 +33,11 @@ Implementation file for the low level input library
reading after \\x1b is read before assuming that escape key was
pressed, and not an escape sequence.
- This is the value used by the readline library.
+ This is the value used by the readline library. It can be overridden by
+ setting the fish_escape_delay_ms variable.
*/
-#define WAIT_ON_ESCAPE 500
+#define WAIT_ON_ESCAPE_DEFAULT 500
+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;
@@ -79,6 +81,7 @@ static int (*interrupt_handler)();
void input_common_init(int (*ih)())
{
interrupt_handler = ih;
+ update_wait_on_escape_ms();
}
void input_common_destroy()
@@ -214,36 +217,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;
}
}