commit c72de8ab0db408dd166f25caafca5c0fee237cf6 from: Mark Jamsek via: Thomas Adam date: Fri Feb 03 15:22:14 2023 UTC tog: add horizontal scroll support to the tree view Suggested by op. tog now supports hscroll in all views so move corresponding keymap docs in tog(1) to global space (this was already the case in tog runtime help). While here, remove some copypasta with a new subroutine to handle hscroll input. ok op@ and stsp@ commit - 66a70b97af464a167c7549a6872b112febae727b commit + c72de8ab0db408dd166f25caafca5c0fee237cf6 blob - a752780caccc9b9007daf5bc95cf05bde851090c blob + 667bfe283076f37b6cb5690da6b2a98d9aae516a --- tog/tog.1 +++ tog/tog.1 @@ -112,6 +112,18 @@ N increments (default: 1). Go to line N in the view (default: last line). .It Cm g Go to line N in the view (default: first line). +.It Cm Right-arrow, l +Scroll view to the right N increments (default: 1). +.br +Output moves left on the screen. +.It Cm Left-arrow, h +Scroll view to the left N increments (default: 1). +.br +Output moves right on the screen. +.It Cm $ +Scroll view to the rightmost position. +.It Cm 0 +Scroll view left to the start of the line. .El .Pp The commands for @@ -145,18 +157,6 @@ are as follows (N denotes optional prefixed count modi Move the selection cursor down N lines (default: 1). .It Cm Up-arrow, k, <, Comma, Ctrl-p Move the selection cursor up N lines (default: 1). -.It Cm Right-arrow, l -Scroll log message field to the right N increments (default: 1). -.br -Log message moves left on the screen. -.It Cm Left-arrow, h -Scroll log message field to the left N increments (default: 1). -.br -Log message moves right on the screen. -.It Cm $ -Scroll log message field to the rightmost position. -.It Cm 0 -Scroll log message field to the leftmost position. .It Cm Page-down, Space, Ctrl+f, f Move the selection cursor down N pages (default: 1). .It Cm Page-up, Ctrl+b, b @@ -313,18 +313,6 @@ detected. Scroll down N lines (default: 1). .It Cm Up-arrow, k, Ctrl-p Scroll up N lines (default: 1). -.It Cm Right-arrow, l -Scroll view to the right N increments (default: 1). -.br -Diff output moves left on the screen. -.It Cm Left-arrow, h -Scroll view to the left N increments (default: 1). -.br -Diff output moves right on the screen. -.It Cm $ -Scroll view to the rightmost position. -.It Cm 0 -Scroll view left to the start of the line. .It Cm Page-down, Space, Ctrl+f, f Scroll down N pages (default: 1). .It Cm Page-up, Ctrl+b, b @@ -430,18 +418,6 @@ are as follows (N denotes optional prefixed count modi Move the selection cursor down N pages (default: 1). .It Cm Up-arrow, k, Ctrl-p Move the selection cursor up N pages (default: 1). -.It Cm Right-arrow, l -Scroll view to the right N increments (default: 1). -.br -File output moves left on the screen. -.It Cm Left-arrow, h -Scroll view to the left N increments (default: 1). -.br -File output moves right on the screen. -.It Cm $ -Scroll view to the rightmost position. -.It Cm 0 -Scroll view left to the start of the line. .It Cm Page-down, Space, Ctrl+f, f Move the selection cursor down N pages (default: 1). .It Cm Page-up, Ctrl+b, b blob - a14163a621b7512437a3ba7028d643f3f5a005b1 blob + 344c266805e9013512993feb7f77e07dc537338f --- tog/tog.c +++ tog/tog.c @@ -3694,7 +3694,37 @@ log_goto_line(struct tog_view *view, int nlines) select_commit(s); return NULL; + +} + +static void +horizontal_scroll_input(struct tog_view *view, int ch) +{ + switch (ch) { + case KEY_LEFT: + case 'h': + view->x -= MIN(view->x, 2); + if (view->x <= 0) + view->count = 0; + break; + case KEY_RIGHT: + case 'l': + if (view->x + view->ncols / 2 < view->maxx) + view->x += 2; + else + view->count = 0; + break; + case '0': + view->x = 0; + break; + case '$': + view->x = MAX(view->maxx - view->ncols / 2, 0); + view->count = 0; + break; + default: + break; + } } static const struct got_error * @@ -3730,24 +3760,12 @@ input_log_view(struct tog_view **new_view, struct tog_ s->quit = 1; break; case '0': - view->x = 0; - break; case '$': - view->x = MAX(view->maxx - view->ncols / 2, 0); - view->count = 0; - break; case KEY_RIGHT: case 'l': - if (view->x + view->ncols / 2 < view->maxx) - view->x += 2; /* move two columns right */ - else - view->count = 0; - break; case KEY_LEFT: case 'h': - view->x -= MIN(view->x, 2); /* move two columns back */ - if (view->x <= 0) - view->count = 0; + horizontal_scroll_input(view, ch); break; case 'k': case KEY_UP: @@ -5304,24 +5322,12 @@ input_diff_view(struct tog_view **new_view, struct tog switch (ch) { case '0': - view->x = 0; - break; case '$': - view->x = MAX(view->maxx - view->ncols / 3, 0); - view->count = 0; - break; case KEY_RIGHT: case 'l': - if (view->x + view->ncols / 3 < view->maxx) - view->x += 2; /* move two columns right */ - else - view->count = 0; - break; case KEY_LEFT: case 'h': - view->x -= MIN(view->x, 2); /* move two columns back */ - if (view->x <= 0) - view->count = 0; + horizontal_scroll_input(view, ch); break; case 'a': case 'w': @@ -6329,24 +6335,12 @@ input_blame_view(struct tog_view **new_view, struct to switch (ch) { case '0': - view->x = 0; - break; case '$': - view->x = MAX(view->maxx - view->ncols / 3, 0); - view->count = 0; - break; case KEY_RIGHT: case 'l': - if (view->x + view->ncols / 3 < view->maxx) - view->x += 2; /* move two columns right */ - else - view->count = 0; - break; case KEY_LEFT: case 'h': - view->x -= MIN(view->x, 2); /* move two columns back */ - if (view->x <= 0) - view->count = 0; + horizontal_scroll_input(view, ch); break; case 'q': s->done = 1; @@ -6784,7 +6778,7 @@ draw_tree_entries(struct tog_view *view, const char *p wchar_t *wline; char *index = NULL; struct tog_color *tc; - int width, n, nentries, i = 1; + int width, n, nentries, scrollx, i = 1; int limit = view->nlines; s->ndisplayed = 0; @@ -6861,6 +6855,7 @@ draw_tree_entries(struct tog_view *view, const char *p te = s->first_displayed_entry; } + view->maxx = 0; for (i = got_tree_entry_get_index(te); i < nentries; i++) { char *line = NULL, *id_str = NULL, *link_target = NULL; const char *modestr = ""; @@ -6907,12 +6902,23 @@ draw_tree_entries(struct tog_view *view, const char *p } free(id_str); free(link_target); - err = format_line(&wline, &width, NULL, line, 0, view->ncols, - 0, 0); + + /* use full line width to determine view->maxx */ + err = format_line(&wline, &width, NULL, line, 0, INT_MAX, 0, 0); if (err) { free(line); break; } + view->maxx = MAX(view->maxx, width); + free(wline); + wline = NULL; + + err = format_line(&wline, &width, &scrollx, line, view->x, + view->ncols, 0, 0); + if (err) { + free(line); + break; + } if (n == s->selected) { if (view->focussed) wstandout(view->window); @@ -6922,7 +6928,7 @@ draw_tree_entries(struct tog_view *view, const char *p if (tc) wattr_on(view->window, COLOR_PAIR(tc->colorpair), NULL); - waddwstr(view->window, wline); + waddwstr(view->window, &wline[scrollx]); if (tc) wattr_off(view->window, COLOR_PAIR(tc->colorpair), NULL); @@ -7396,6 +7402,14 @@ input_tree_view(struct tog_view **new_view, struct tog return tree_goto_line(view, nscroll); switch (ch) { + case '0': + case '$': + case KEY_RIGHT: + case 'l': + case KEY_LEFT: + case 'h': + horizontal_scroll_input(view, ch); + break; case 'i': s->show_ids = !s->show_ids; view->count = 0; @@ -8307,24 +8321,12 @@ input_ref_view(struct tog_view **new_view, struct tog_ switch (ch) { case '0': - view->x = 0; - break; case '$': - view->x = MAX(view->maxx - view->ncols / 2, 0); - view->count = 0; - break; case KEY_RIGHT: case 'l': - if (view->x + view->ncols / 2 < view->maxx) - view->x += 2; - else - view->count = 0; - break; case KEY_LEFT: case 'h': - view->x -= MIN(view->x, 2); - if (view->x <= 0) - view->count = 0; + horizontal_scroll_input(view, ch); break; case 'i': s->show_ids = !s->show_ids; @@ -8938,24 +8940,12 @@ input_help_view(struct tog_view **new_view, struct tog switch (ch) { case '0': - view->x = 0; - break; case '$': - view->x = MAX(view->maxx - view->ncols / 3, 0); - view->count = 0; - break; case KEY_RIGHT: case 'l': - if (view->x + view->ncols / 3 < view->maxx) - view->x += 2; - else - view->count = 0; - break; case KEY_LEFT: case 'h': - view->x -= MIN(view->x, 2); - if (view->x <= 0) - view->count = 0; + horizontal_scroll_input(view, ch); break; case 'g': case KEY_HOME: