summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--more.c68
1 files changed, 33 insertions, 35 deletions
diff --git a/more.c b/more.c
index ed03b6a..83e6077 100644
--- a/more.c
+++ b/more.c
@@ -396,6 +396,27 @@ static struct more_file more_examine(struct more_file *mf)
return *mf;
}
+static struct more_file * more_next(struct more_file *mf, int n)
+{
+ more_close(mf);
+
+ if (n > 0) {
+ while (n-- > 0 && mf->next) {
+ mf = mf->next;
+ }
+ } else {
+ while (n++ < 0 && mf->prev) {
+ mf = mf->prev;
+ }
+ }
+
+ more_open(mf);
+ wclear(more_win);
+ wmove(more_win, 0, 0);
+ more_refresh(mf);
+ return mf;
+}
+
static int more(struct more_file *mf)
{
if (more_open(mf) != 0) {
@@ -430,7 +451,8 @@ static int more(struct more_file *mf)
case 'f':
case CTRL_F:
if (at_eof) {
- return 1;
+ mf = more_next(mf, 1);
+ break;
}
if (count == 0) {
@@ -453,7 +475,8 @@ static int more(struct more_file *mf)
case 'j':
case '\n':
if (at_eof) {
- return 1;
+ mf = more_next(mf, 1);
+ break;
}
more_scroll(mf, count, 1);
break;
@@ -465,14 +488,15 @@ static int more(struct more_file *mf)
case 'd':
case CTRL_D:
if (at_eof) {
- return 1;
+ mf = more_next(mf, 1);
+ break;
}
more_scroll(mf, count, (LINES - 1) / 2);
break;
case 's':
if (at_eof) {
- return 1;
+ mf = more_next(mf, 1);
}
count = count ? count : 1;
more_scroll(mf, LINES - 1 + count, 1);
@@ -536,38 +560,12 @@ static int more(struct more_file *mf)
more_examine(mf);
break;
- case 'n':
- if (mf->next == NULL) {
- /* TODO */
- return 0;
- }
- more_close(mf);
- if (count == 0) {
- count = 1;
- }
- while (count-- > 0 && mf->next) {
- mf = mf->next;
- }
- wprintw(more_status, "%s", mf->path);
- more_open(mf);
- clear();
- more_refresh(mf);
- break;
-
case 'p':
- if (mf->prev == NULL) {
- break;
- }
- more_close(mf);
- if (count == 0) {
- count = 1;
- }
- while (count-- > 0 && mf->prev) {
- mf = mf->prev;
- }
- more_open(mf);
- clear();
- more_refresh(mf);
+ count = count ? -count : -1;
+ /* FALLTHRU */
+ case 'n':
+ count = count ? count : 1;
+ mf = more_next(mf, count);
break;
case 't':