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

From:
Omar Polo <op@omarpolo.com>
Subject:
Re: tog: abort compound command
To:
Mark Jamsek <mark@jamsek.com>
Cc:
gameoftrees@openbsd.org
Date:
Sat, 02 Jul 2022 15:48:06 +0200

Download raw body.

Thread
Mark Jamsek <mark@jamsek.com> wrote:
> stsp noticed that if you run 9999j in the log view, in a large enough
> repo you have to wait till 9999 lines have been scrolled, or in
> smaller repos until the end of the commit history.
> 
> This enables aborting the command with C-g or backspace.
> 
> I remembered both op and naddy were partial to C-g abort semantics, so
> for consistency I've added C-g to the existing backspace option to abort
> search and G in log view.
> 
> The diff also removes a couple trailing whitespace in tog.1

had the same issues as stsp with tog.1, but the diff reads fine and the
edits in tog.c works perfectly!

ok op@

> diff /home/mark/src/git/got-current
> commit - f0032ce63b4f4f035e5f7894a406a96931f99f3f
> path + /home/mark/src/git/got-current
> blob - 18d37fe0f1b21d153863f1bcf024ecca990a307a
> file + tog/tog.1
> --- 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 - 9cc2f49357acdfea63b9c2c89ad3b280d9054d53
> file + tog/tog.c
> --- tog/tog.c
> +++ tog/tog.c
> @@ -972,12 +972,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;
> 
> @@ -1072,22 +1074,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();
> @@ -2556,7 +2565,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;
>  		}
> @@ -2921,7 +2930,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);