tog: add C-g/backspace key map to abort compound cmds Problem reported by stsp: 9999j would tie up tog till completed. While here, trim trailing whitespace in tog.1 and make C-g alias existing backspace abort key map for search and G in log view. ok op@ and stsp@
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
diff --git a/tog/tog.1 b/tog/tog.1
index 18d37fe..52b2067 100644
--- a/tog/tog.1
+++ b/tog/tog.1
@@ -62,6 +62,10 @@ operation as indicated.
will echo digits to the screen when count modifiers are entered, and complete
the sequence upon input of the first non-numeric character.
Count modifiers can be aborted by entering an unmapped key.
+Once a compound command is executed, the operation can be cancelled with
+.Cm C-g
+or
+.Cm Backspace .
The global key bindings are:
.Bl -tag -width Ds
.It Cm Q
@@ -138,6 +142,8 @@ Move the cursor to the oldest commit.
This will traverse all commits on the current branch which may take
a long time depending on the number of commits in branch history.
If needed, this operation can be cancelled with
+.Cm C-g
+or
.Cm Backspace .
.It Cm Enter
Open a
@@ -163,14 +169,18 @@ Regular expression syntax is documented in
.It Cm n
Find the Nth next commit which matches the current search pattern (default: 1).
.br
-Searching continues until either a match is found or the
+Searching continues until either a match is found or
+.Cm C-g
+or the
.Cm Backspace
key is pressed.
.It Cm N
Find the Nth previous commit which matches the current search pattern
(default: 1).
.br
-Searching continues until either a match is found or the
+Searching continues until either a match is found or
+.Cm C-g
+or the
.Cm Backspace
key is pressed.
.It Cm Ctrl+l
@@ -295,7 +305,7 @@ Find the Nth previous line which matches the current search pattern
Toggle display of whitespace-only changes.
.It Cm A
Change the diff algorithm.
-Supported diff algorithms are Myers and Patience.
+Supported diff algorithms are Myers and Patience.
This is a global setting which also affects the
.Cm blame
view.
@@ -385,7 +395,7 @@ Find the Nth previous line which matches the current search pattern
(default: 1).
.It Cm A
Change the diff algorithm.
-Supported diff algorithms are Myers and Patience.
+Supported diff algorithms are Myers and Patience.
This is a global setting which also affects the
.Cm diff
view.
diff --git a/tog/tog.c b/tog/tog.c
index a81a484..95a351a 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -978,12 +978,14 @@ view_search_start(struct tog_view *view)
mvwaddstr(v->window, v->nlines - 1, 0, "/");
wclrtoeol(v->window);
+ nodelay(view->window, FALSE); /* block for search term input */
nocbreak();
echo();
ret = wgetnstr(v->window, pattern, sizeof(pattern));
wrefresh(v->window);
cbreak();
noecho();
+ nodelay(view->window, TRUE);
if (ret == ERR)
return NULL;
@@ -1077,14 +1079,21 @@ view_input(struct tog_view **new, int *done, struct tog_view *view,
return NULL;
}
- nodelay(stdscr, FALSE);
+ nodelay(view->window, FALSE);
/* Allow threads to make progress while we are waiting for input. */
errcode = pthread_mutex_unlock(&tog_mutex);
if (errcode)
return got_error_set_errno(errcode, "pthread_mutex_unlock");
- /* If we have an unfinished count, don't get a new key map. */
- ch = view->ch;
- if ((view->count && --view->count == 0) || !view->count) {
+ /* If we have an unfinished count, let C-g or backspace abort. */
+ if (view->count && --view->count) {
+ cbreak();
+ nodelay(view->window, TRUE);
+ ch = wgetch(view->window);
+ if (ch == CTRL('g') || ch == KEY_BACKSPACE)
+ view->count = 0;
+ else
+ ch = view->ch;
+ } else {
ch = wgetch(view->window);
if (ch >= '1' && ch <= '9')
view->ch = ch = get_compound_key(view, ch);
@@ -1092,7 +1101,7 @@ view_input(struct tog_view **new, int *done, struct tog_view *view,
errcode = pthread_mutex_lock(&tog_mutex);
if (errcode)
return got_error_set_errno(errcode, "pthread_mutex_lock");
- nodelay(stdscr, TRUE);
+ nodelay(view->window, TRUE);
if (tog_sigwinch_received || tog_sigcont_received) {
tog_resizeterm();
@@ -2561,7 +2570,7 @@ search_next_log_view(struct tog_view *view)
if (errcode)
return got_error_set_errno(errcode,
"pthread_mutex_lock");
- if (ch == KEY_BACKSPACE) {
+ if (ch == CTRL('g') || ch == KEY_BACKSPACE) {
view->search_next_done = TOG_SEARCH_HAVE_MORE;
return NULL;
}
@@ -2925,7 +2934,7 @@ input_log_view(struct tog_view **new_view, struct tog_view *view, int ch)
int begin_x = 0, begin_y = 0, eos, n, nscroll;
if (s->thread_args.load_all) {
- if (ch == KEY_BACKSPACE)
+ if (ch == CTRL('g') || ch == KEY_BACKSPACE)
s->thread_args.load_all = 0;
else if (s->thread_args.log_complete) {
err = log_move_cursor_down(view, s->commits.ncommits);