commit - 9b6978794ceef93ae5f616c11f62b66c71038c43
commit + b304db33392ed26f1cc70bcf734308e485459658
blob - 312fb7bb91121eebf0c8a63d05b7268dfe15b324
blob + ea595b46157840dd6d4fcc289592379a6748b1c9
--- tog/tog.c
+++ tog/tog.c
fprintf(stderr, "usage: %s diff [repository-path] object1 object2\n",
getprogname());
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 *
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;
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');
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))
case KEY_UP:
case KEY_BACKSPACE:
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':
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;
}