implement page down/up scrolling in tog diff view
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/tog/tog.c b/tog/tog.c
index 312fb7b..ea595b4 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -775,23 +775,34 @@ usage_diff(void)
exit(1);
}
+static char *
+parse_next_line(FILE *f, size_t *len)
+{
+ char *line;
+ size_t linelen;
+ size_t lineno;
+ const char delim[3] = { '\0', '\0', '\0'};
+
+ line = fparseln(f, &linelen, &lineno, delim, 0);
+ if (len)
+ *len = linelen;
+ return line;
+}
+
static const struct got_error *
draw_diff(FILE *f, int *first_displayed_line, int *last_displayed_line,
int *eof, int max_lines)
{
int nlines = 0, nprinted = 0;
+ char *line;
+ size_t len;
rewind(f);
wclear(tog_diff_view.window);
*eof = 0;
while (nprinted < max_lines) {
- char *line;
- size_t lineno;
- size_t linelen;
- const char delim[3] = { '\0', '\0', '\0'};
-
- line = fparseln(f, &linelen, &lineno, delim, 0);
+ line = parse_next_line(f, &len);
if (line == NULL) {
*eof = 1;
break;
@@ -801,7 +812,7 @@ draw_diff(FILE *f, int *first_displayed_line, int *last_displayed_line,
continue;
}
- if (linelen > COLS - 1)
+ if (len > COLS - 1)
line[COLS - 1] = '\0';
waddstr(tog_diff_view.window, line);
waddch(tog_diff_view.window, '\n');
@@ -824,7 +835,7 @@ show_diff_view(struct got_object *obj1, struct got_object *obj2,
const struct got_error *err;
FILE *f;
int ch, done = 0, first_displayed_line = 1, last_displayed_line = LINES;
- int eof;
+ int eof, i;
if (obj1 != NULL && obj2 != NULL &&
got_object_get_type(obj1) != got_object_get_type(obj2))
@@ -881,6 +892,11 @@ show_diff_view(struct got_object *obj1, struct got_object *obj2,
if (first_displayed_line > 1)
first_displayed_line--;
break;
+ case KEY_PPAGE:
+ i = 0;
+ while (i++ < LINES - 1 && first_displayed_line > 1)
+ first_displayed_line--;
+ break;
case 'j':
case KEY_DOWN:
case KEY_ENTER:
@@ -888,6 +904,15 @@ show_diff_view(struct got_object *obj1, struct got_object *obj2,
if (!eof)
first_displayed_line++;
break;
+ case KEY_NPAGE:
+ i = 0;
+ while (!eof && i++ < LINES - 1) {
+ char *line = parse_next_line(f, NULL);
+ first_displayed_line++;
+ if (line == NULL)
+ break;
+ }
+ break;
default:
break;
}