summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--more.c59
1 files changed, 43 insertions, 16 deletions
diff --git a/more.c b/more.c
index 19184b8..11d2454 100644
--- a/more.c
+++ b/more.c
@@ -105,7 +105,7 @@ static int more_open(struct more_file *mf)
{
mf->f = stdin;
- if (strcmp(mf->path, "-")) {
+ if (mf->path && strcmp(mf->path, "-")) {
mf->f = fopen(mf->path, "r");
if (!mf->f) {
fprintf(stderr, "more: %s: %s\r\n", mf->path, strerror(errno));
@@ -123,6 +123,10 @@ static int more_open(struct more_file *mf)
mf->nbytes = st.st_size;
}
+ if (mf->path == NULL) {
+ mf->path = "<STDIN>";
+ }
+
return 0;
}
@@ -151,6 +155,7 @@ static void more_refresh(struct more_file *mf)
wprintw(more_win, "%s", mf->buf);
}
+ wrefresh(more_win);
}
static void more_scroll(struct more_file *mf, int count, int multiple)
@@ -162,23 +167,25 @@ static void more_scroll(struct more_file *mf, int count, int multiple)
}
if (by < 0) {
- wscrl(more_win, by);
if ((size_t)(-by) > mf->topline) {
+ by = -mf->topline;
mf->topline = 0;
} else {
mf->topline += by;
}
- more_refresh(mf);
+ if (by != 0) {
+ wscrl(more_win, by);
+ more_refresh(mf);
+ }
return;
}
- while (by-- >= 0) {
+ while (by-- > 0) {
/* FIXME: account for long lines here, too */
-
- mf->topline++;
if (more_getline(mf, mf->topline + LINES) < 0) {
break;
}
+ mf->topline++;
wprintw(more_win, "%s", mf->buf);
}
}
@@ -306,10 +313,8 @@ static struct more_file more_invoke_editor(struct more_file *mf)
static struct more_file more_examine(struct more_file *mf)
{
wprintw(more_status, "e");
- echo();
char filename[1024];
wgetnstr(more_status, filename, sizeof(filename));
- noecho();
wclear(more_status);
wordexp_t we = { 0 };
@@ -356,10 +361,9 @@ static int more(struct more_file *mf)
}
more_refresh(mf);
- wrefresh(more_win);
int count = 0;
- while (mf->f) {
+ while (mf) {
int at_eof = 0; //(mf.topline + LINES >= mf.nlines);
wmove(more_status, 0, 0);
if (at_eof) {
@@ -447,6 +451,7 @@ static int more(struct more_file *mf)
/* FALLTHRU */
case 'r':
case CTRL_L:
+ wclear(more_win);
more_refresh(mf);
break;
@@ -476,9 +481,7 @@ static int more(struct more_file *mf)
case ':':
waddch(more_status, c);
- echo();
int c2 = wgetch(more_status);
- noecho();
wprintw(more_status, "\b \b");
@@ -488,12 +491,38 @@ static int more(struct more_file *mf)
break;
case 'n':
+ if (mf->next == NULL) {
+ /* TODO */
+ return 0;
+ }
more_close(mf);
- return count ? count : 1;
+ 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);
- return count ? -count : -1;
+ if (count == 0) {
+ count = 1;
+ }
+ while (count-- > 0 && mf->prev) {
+ mf = mf->prev;
+ }
+ more_open(mf);
+ clear();
+ more_refresh(mf);
+ break;
case 't':
// tagstring();
@@ -547,7 +576,6 @@ static int more(struct more_file *mf)
wrefresh(more_win);
}
- more_close(mf);
return 0;
}
@@ -708,7 +736,6 @@ int main(int argc, char *argv[])
newterm(NULL, stdout, tty);
}
cbreak();
- noecho();
atexit(more_exit);