From: Stefan Sperling Subject: Re: tog: handle Home/End for log and diff views To: Jasper Lievisse Adriaanse Cc: gameoftrees@openbsd.org Date: Mon, 30 Aug 2021 19:36:15 +0200 On Mon, Aug 30, 2021 at 02:19:10PM +0200, Jasper Lievisse Adriaanse wrote: > On Mon, Aug 30, 2021 at 12:53:29PM +0200, Stefan Sperling wrote: > > As we discussed over lunch, there should be a way for users to abort > > loading in case they hit the key by accident. Backspace is already > > bound for this purpose while searching. Perhaps we can generalize > > Backspace to abort loading in general? In any case, if we want to > > support cancellation it could be added in a follow-up patch. > > Generalizing that would be preferable so we don't add individual hacks > for all future additions. Also we could make it so that any operation > involving the logger thread could be canceled. This is a patch I came up with in order to solve the immediate usability issue. It allows for cancellation with backspace in case the user triggers the load operation by accident. If you think it could be generalized further such changes could be committed on top of this diff. ok? diff 93f8a3371abdcbfdc9e411ff44942acb0198ca47 /home/stsp/src/got blob - f19156ff60b8708acea73670fd8fd33b02ae8c31 file + tog/tog.c --- tog/tog.c +++ tog/tog.c @@ -304,6 +304,7 @@ struct tog_log_thread_args { pthread_cond_t need_commits; pthread_cond_t commit_loaded; int commits_needed; + int load_all; struct got_commit_graph *graph; struct commit_queue *commits; const char *in_repo_path; @@ -885,8 +886,6 @@ view_input(struct tog_view **new, int *done, struct to } switch (ch) { - case ERR: - break; case '\t': if (view->child) { view->focussed = 0; @@ -1612,7 +1611,7 @@ draw_commits(struct tog_view *view) if (s->thread_args.commits_needed == 0) halfdelay(10); /* disable fast refresh */ - if (s->thread_args.commits_needed > 0) { + if (s->thread_args.commits_needed > 0 || s->thread_args.load_all) { if (asprintf(&ncommits_str, " [%d/%d] %s", entry ? entry->idx + 1 : 0, s->commits.ncommits, (view->searching && !view->search_next_done) ? @@ -1762,7 +1761,7 @@ trigger_log_thread(struct tog_view *view, int wait) halfdelay(1); /* fast refresh while loading commits */ - while (ta->commits_needed > 0) { + while (ta->commits_needed > 0 || ta->load_all) { if (ta->log_complete) break; @@ -2028,7 +2027,7 @@ log_thread(void *arg) return (void *)err; err = NULL; done = 1; - } else if (a->commits_needed > 0) + } else if (a->commits_needed > 0 && !a->load_all) a->commits_needed--; errcode = pthread_mutex_lock(&tog_mutex); @@ -2055,7 +2054,7 @@ log_thread(void *arg) if (done) a->commits_needed = 0; else { - if (a->commits_needed == 0) { + if (a->commits_needed == 0 && !a->load_all) { errcode = pthread_cond_wait(&a->need_commits, &tog_mutex); if (errcode) @@ -2391,6 +2390,15 @@ input_log_view(struct tog_view **new_view, struct tog_ int begin_x = 0; switch (ch) { + case ERR: /* no user input from wgetch() */ + if (s->thread_args.load_all && s->thread_args.log_complete) { + s->thread_args.load_all = 0; + log_scroll_down(view, s->commits.ncommits); + s->selected = MIN(view->nlines - 2, + s->commits.ncommits - 1); + select_commit(s); + } + break; case 'q': s->quit = 1; break; @@ -2446,16 +2454,11 @@ input_log_view(struct tog_view **new_view, struct tog_ case KEY_END: { /* We don't know yet how many commits, so we're forced to * traverse them all. */ - while (1) { - if (s->thread_args.log_complete) - break; - - s->thread_args.commits_needed++; - err = trigger_log_thread(view, 1); - if (err) - return err; + if (!s->thread_args.log_complete) { + s->thread_args.load_all = 1; + return trigger_log_thread(view, 0); } - + log_scroll_down(view, s->commits.ncommits); s->selected = MIN(view->nlines - 2, s->commits.ncommits - 1); select_commit(s); @@ -2540,6 +2543,10 @@ input_log_view(struct tog_view **new_view, struct tog_ case KEY_BACKSPACE: case CTRL('l'): case 'B': + if (ch == KEY_BACKSPACE && s->thread_args.load_all) { + s->thread_args.load_all = 0; + break; + } if (ch == KEY_BACKSPACE && got_path_is_root_dir(s->in_repo_path)) break;