From: Mark Jamsek Subject: tog: add horizontal scrolling to the ref view To: Game of Trees Date: Wed, 1 Feb 2023 18:14:36 +1100 As per the subject line, given ref entries can be quite long, especially if the last modified date and ID is displayed (with 'm' and 'i' keymaps, respectively), I figure we should support horizontal scrolling in this view too. ok? ----------------------------------------------- commit 58b4cc4632fdcc6cd3a62a7a0678189680e7b78d (main) from: Mark Jamsek date: Wed Feb 1 07:01:28 2023 UTC tog: add horizontal scroll to the ref view M tog/tog.c | 35+ 4- 1 file changed, 35 insertions(+), 4 deletions(-) diff fa64fb25c20a748986758db1d7c9a333c2e71d0b 58b4cc4632fdcc6cd3a62a7a0678189680e7b78d commit - fa64fb25c20a748986758db1d7c9a333c2e71d0b commit + 58b4cc4632fdcc6cd3a62a7a0678189680e7b78d blob - 18fd85d80ae64e33a4203855e707a424341027e8 blob + 73869bfa87df9af7a68e8ec4c44690f950d74ccb --- tog/tog.c +++ tog/tog.c @@ -8059,7 +8059,7 @@ show_ref_view(struct tog_view *view) char *line = NULL; wchar_t *wline; struct tog_color *tc; - int width, n; + int width, n, scrollx; int limit = view->nlines; werase(view->window); @@ -8097,6 +8097,7 @@ show_ref_view(struct tog_view *view) return NULL; n = 0; + view->maxx = 0; while (re && limit > 0) { char *line = NULL; char ymd[13]; /* YYYY-MM-DD + " " + NUL */ @@ -8164,12 +8165,22 @@ show_ref_view(struct tog_view *view) got_ref_get_name(re->ref)) == -1) return got_error_from_errno("asprintf"); - 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); return err; } + 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); + return err; + } if (n == s->selected) { if (view->focussed) wstandout(view->window); @@ -8179,7 +8190,7 @@ show_ref_view(struct tog_view *view) 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); @@ -8290,6 +8301,26 @@ input_ref_view(struct tog_view **new_view, struct tog_ return ref_goto_line(view, nscroll); 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; + break; case 'i': s->show_ids = !s->show_ids; view->count = 0; -- Mark Jamsek GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68