"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Mark Jamsek <mark@jamsek.com>
Subject:
tog: user-defined keymap timeout
To:
gameoftrees@openbsd.org
Date:
Tue, 28 Jun 2022 17:41:03 +1000

Download raw body.

Thread
As Stefan suggested in the original thread, enable user-defined timeout
for compound keymaps, configurable with an envvar. This also increases
the default value to 1 second (up from 0.5s).

diff refs/heads/main refs/heads/dev/nkeymap
blob - 728ba5ee9e20edbde20ed7f0c2ff1cbabad89c0b
blob + 7acca5d60fb3d0dfb62ffe6c1848aa16315f03c3
--- tog/tog.1
+++ tog/tog.1
@@ -64,6 +64,11 @@ will wait 500 milliseconds for each successive integer
 to complete.
 If this sequence should timeout or does not conclude with a valid key binding,
 the command is aborted and any preceding count is reset.
+This behavior can be customized with the TOG_KEYMAP_TIMEOUT environment
+variable.
+See
+.Sx ENVIRONMENT
+for details.
 The global key bindings are:
 .Bl -tag -width Ds
 .It Cm Q
@@ -561,6 +566,12 @@ work tree, use the repository path associated with thi
 .El
 .Sh ENVIRONMENT
 .Bl -tag -width TOG_COLORS
+.It Ev TOG_KEYMAP_TIMEOUT
+Define the timeout interval between compound sequence keypresses.
+The value must be an integer between 1 and 255, and specifies how many tenths
+of a second
+.Nm
+will wait before timing out (default: 10).
 .It Ev TOG_COLORS
 .Nm
 shows colorized output if this variable is set to a non-empty value.
blob - 87eeaf0b99951e273aa30da21d81e7ab116412c7
blob + 6f9bc97a1dbc436514494bb9e7f79b8ea9e5be02
--- tog/tog.c
+++ tog/tog.c
@@ -504,6 +504,7 @@ struct tog_view {
 	int lines, cols; /* copies of LINES and COLS */
 	int ch, count; /* current keymap and count prefix */
 	int focussed; /* Only set on one parent or child view at a time. */
+	int timeout; /* timeout for compound key maps (default: 10=1s) */
 	int dying;
 	struct tog_view *parent;
 	struct tog_view *child;
@@ -899,7 +900,7 @@ get_compound_key(struct tog_view *view, int c)
 	int x, n = 0;

 	view->count = 0;
-	halfdelay(5);  /* block for half a second */
+	halfdelay(view->timeout);  /* timeout interval between keys */
 	wattron(view->window, A_BOLD);
 	wmove(view->window, view->nlines - 1, 0);
 	wclrtoeol(view->window);
@@ -927,6 +928,20 @@ get_compound_key(struct tog_view *view, int c)
 	return c;
 }

+static void
+set_keymap_timeout(struct tog_view *view)
+{
+	const char *timeout;
+
+	/* fallback to default on error or if not set */
+	timeout = getenv("TOG_KEYMAP_TIMEOUT");
+	if (timeout != NULL)
+		view->timeout = strtonum(timeout, 1, 255, NULL);
+
+	if (!view->timeout)
+		view->timeout = 10;
+}
+
 static const struct got_error *
 view_input(struct tog_view **new, int *done, struct tog_view *view,
     struct tog_view_list_head *views)
@@ -2542,6 +2557,9 @@ open_log_view(struct tog_view *view, struct got_object
 		}
 	}

+	if (!view->timeout)
+		set_keymap_timeout(view);
+
 	view->show = show_log_view;
 	view->input = input_log_view;
 	view->close = close_log_view;
@@ -4001,6 +4019,9 @@ open_diff_view(struct tog_view *view, struct got_objec
 			goto done;
 	}

+	if (!view->timeout)
+		set_keymap_timeout(view);
+
 	if (log_view && view_is_splitscreen(view))
 		show_log_view(log_view); /* draw vborder */
 	diff_view_indicate_progress(view);
@@ -4917,6 +4938,9 @@ open_blame_view(struct tog_view *view, char *path,
 			return err;
 	}

+	if (!view->timeout)
+		set_keymap_timeout(view);
+
 	view->show = show_blame_view;
 	view->input = input_blame_view;
 	view->close = close_blame_view;
@@ -5855,6 +5879,9 @@ open_tree_view(struct tog_view *view, struct got_objec
 			goto done;
 	}

+	if (!view->timeout)
+		set_keymap_timeout(view);
+
 	view->show = show_tree_view;
 	view->input = input_tree_view;
 	view->close = close_tree_view;
@@ -6471,6 +6498,9 @@ open_ref_view(struct tog_view *view, struct got_reposi
 			goto done;
 	}

+	if (!view->timeout)
+		set_keymap_timeout(view);
+
 	view->show = show_ref_view;
 	view->input = input_ref_view;
 	view->close = close_ref_view;


-- 
Mark Jamsek <fnc.bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68