Download raw body.
implement tog ref command
On Tue, Nov 24, 2020 at 11:46:40PM +0100, Christian Weisgerber wrote:
> Stefan Sperling:
>
> > > * If I run tog ref in a repository and window where the number of
> > > refs (r) compares to the number of window lines (w) like
> > > w < r < 2w, then page down from the initial position displays the
> > > next to last entry on the bottom line and no entry is selected.
> >
> > I cannot reproduce this, sorry. In a small xterm with something like 6
> > lines visible, and a repository with 25 refs, page-down seems to do
> > the right thing. Can you give me step-by-step instructions?
>
> Try with a 15-line xterm. I see it with more than one page worth
> of refs, but less than two pages. E.g., my got.git here has 51
> refs and I can reproduce it with a 30-line xterm, but not the
> standard 24-line one.
This patch aligns page-down/up scrolling in the ref view with the
implementation we're now using for the tree view.
Does it now behave as you expect?
diff 19366d097e5368b7850c41aa2dfb2587054eb22e 929417b62d3f83be11a11cf2eb98a6e1d0d74941
blob - 1e86a0b31d06f8b7654c3cf6f435d952ee57bb6b
blob + 37a8fe8842d345b89c8c004db5cb3f7c0adcf699
--- tog/tog.c
+++ tog/tog.c
@@ -5705,7 +5705,6 @@ open_ref_view(struct tog_view *view, struct got_reposi
const struct got_error *err = NULL;
struct tog_ref_view_state *s = &view->state.ref;
- s->first_displayed_entry = 0;
s->selected_entry = 0;
s->repo = repo;
@@ -5717,6 +5716,8 @@ open_ref_view(struct tog_view *view, struct got_reposi
if (err)
return err;
+ s->first_displayed_entry = TAILQ_FIRST(&s->refs);
+
if (has_colors() && getenv("TOG_COLORS") != NULL) {
err = add_color(&s->colors, "^refs/heads/",
TOG_COLOR_REFS_HEADS,
@@ -5856,20 +5857,22 @@ ref_scroll_up(struct tog_view *view,
struct tog_reflist_entry **first_displayed_entry, int maxscroll,
struct tog_reflist_head *refs)
{
- int i;
+ struct tog_reflist_entry *re;
+ int i = 0;
if (*first_displayed_entry == TAILQ_FIRST(refs))
return;
- i = 0;
- while (*first_displayed_entry && i < maxscroll) {
- *first_displayed_entry = TAILQ_PREV(*first_displayed_entry,
- tog_reflist_head, entry);
- i++;
+ re = TAILQ_PREV(*first_displayed_entry, tog_reflist_head, entry);
+ while (i++ < maxscroll) {
+ if (re == NULL)
+ break;
+ *first_displayed_entry = re;
+ re = TAILQ_PREV(re, tog_reflist_head, entry);
}
}
-static int
+static void
ref_scroll_down(struct tog_reflist_entry **first_displayed_entry, int maxscroll,
struct tog_reflist_entry *last_displayed_entry,
struct tog_reflist_head *refs)
@@ -5890,7 +5893,6 @@ ref_scroll_down(struct tog_reflist_entry **first_displ
next = TAILQ_NEXT(next, entry);
}
}
- return n;
}
static const struct got_error *
@@ -5994,10 +5996,7 @@ show_ref_view(struct tog_view *view)
if (limit == 0)
return NULL;
- if (s->first_displayed_entry)
- re = s->first_displayed_entry;
- else
- re = TAILQ_FIRST(&s->refs);
+ re = s->first_displayed_entry;
if (asprintf(&line, "references [%d/%d]", re->idx + s->selected + 1,
s->nrefs) == -1)
@@ -6148,7 +6147,7 @@ input_ref_view(struct tog_view **new_view, struct tog_
const struct got_error *err = NULL;
struct tog_ref_view_state *s = &view->state.ref;
struct tog_view *log_view, *tree_view;
- int begin_x = 0, nscrolled;
+ int begin_x = 0;
switch (ch) {
case 'i':
@@ -6203,18 +6202,16 @@ input_ref_view(struct tog_view **new_view, struct tog_
case KEY_UP:
if (s->selected > 0) {
s->selected--;
- if (s->selected == 0)
- break;
+ break;
}
- if (s->selected > 0)
- break;
ref_scroll_up(view, &s->first_displayed_entry, 1, &s->refs);
break;
case KEY_PPAGE:
case CTRL('b'):
+ if (s->first_displayed_entry == TAILQ_FIRST(&s->refs))
+ s->selected = 0;
ref_scroll_up(view, &s->first_displayed_entry,
- MAX(0, view->nlines - 4 - s->selected), &s->refs);
- s->selected = 0;
+ MAX(0, view->nlines - 1), &s->refs);
break;
case 'j':
case KEY_DOWN:
@@ -6236,18 +6233,8 @@ input_ref_view(struct tog_view **new_view, struct tog_
s->selected = s->ndisplayed - 1;
break;
}
- nscrolled = ref_scroll_down(&s->first_displayed_entry,
- view->nlines, s->last_displayed_entry, &s->refs);
- if (nscrolled < view->nlines) {
- int ndisplayed = 0;
- struct tog_reflist_entry *re;
- re = s->first_displayed_entry;
- do {
- ndisplayed++;
- re = TAILQ_NEXT(re, entry);
- } while (re);
- s->selected = ndisplayed - 1;
- }
+ ref_scroll_down(&s->first_displayed_entry,
+ view->nlines - 1, s->last_displayed_entry, &s->refs);
break;
case CTRL('l'):
ref_view_free_refs(s);
implement tog ref command