commit a6d37facd3db72c084380ebec6d6160ad8ee4763 from: Mark Jamsek date: Sun Jul 03 10:54:48 2022 UTC 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@ commit - 49b24ee54927319519e1a84959f9f4040f4dc16e commit + a6d37facd3db72c084380ebec6d6160ad8ee4763 blob - 18d37fe0f1b21d153863f1bcf024ecca990a307a blob + 52b2067e76aa6fd1c89b05b078332d4681b010f3 --- tog/tog.1 +++ 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 s 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 s (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. blob - a81a484bfa36bb1af49fb9a70c6949abe4550cf2 blob + 95a351a042eb915c3180784da0a53b2c2d2abca1 --- tog/tog.c +++ 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,22 +1079,29 @@ view_input(struct tog_view **new, int *done, struct to 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); } 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_ 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);