commit 66a70b97af464a167c7549a6872b112febae727b from: Mark Jamsek via: Thomas Adam date: Fri Feb 03 15:22:13 2023 UTC tog: add horizontal scroll support to the ref view ok op@ and stsp@ commit - 5c3a0a1a77196a588cb572b326aef1eb4fb23fb3 commit + 66a70b97af464a167c7549a6872b112febae727b blob - 6d8d3e63b5b6044a222ed9586b1638c36fad2a57 blob + a14163a621b7512437a3ba7028d643f3f5a005b1 --- tog/tog.c +++ tog/tog.c @@ -8064,7 +8064,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); @@ -8102,6 +8102,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 */ @@ -8169,12 +8170,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); @@ -8184,7 +8195,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); @@ -8295,6 +8306,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;