summaryrefslogtreecommitdiff
path: root/more.c
diff options
context:
space:
mode:
Diffstat (limited to 'more.c')
-rw-r--r--more.c63
1 files changed, 43 insertions, 20 deletions
diff --git a/more.c b/more.c
index 574db4f..e1a1b9b 100644
--- a/more.c
+++ b/more.c
@@ -2,6 +2,7 @@
#include <curses.h>
#include <ctype.h>
#include <errno.h>
+#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -10,6 +11,7 @@
#include "more.h"
+static int more_clear = 0;
static int retval = 0;
enum {
@@ -21,7 +23,7 @@ enum {
CTRL_U = 0x15,
};
-static void man_refresh(struct more_file *mf)
+static void more_refresh(struct more_file *mf)
{
for (size_t i = mf->topline; i < mf->topline + LINES - 1; i++) {
/* FIXME: account for long lines */
@@ -34,9 +36,12 @@ static void man_refresh(struct more_file *mf)
}
}
-static void man_scroll(struct more_file *mf, int count, int multiple)
+static void more_scroll(struct more_file *mf, int count, int multiple)
{
int by = count ? count * multiple : multiple;
+ if (abs(by) >= LINES && more_clear) {
+ clear();
+ }
if (by < 0) {
scrl(by);
@@ -45,12 +50,12 @@ static void man_scroll(struct more_file *mf, int count, int multiple)
} else {
mf->topline += by;
}
- man_refresh(mf);
+ more_refresh(mf);
} else while (by-- > 0) {
/* FIXME: account for long lines here, too */
mf->topline++;
- if (more_getline(mf, mf->topline + LINES + 1) < 0) {
+ if (more_getline(mf, mf->topline + LINES - 1) < 0) {
break;
}
printw("%s", mf->buf);
@@ -72,10 +77,28 @@ static void jump(struct more_file *mf)
int c = getch();
if (islower(c)) {
mf->topline = mf->mark[c - 'a'];
- man_refresh(mf);
+ more_refresh(mf);
}
}
+static struct more_file more_examine(struct more_file *mf)
+{
+ printw("e ");
+ refresh();
+ echo();
+ char filename[1024];
+ getnstr(filename, sizeof(filename));
+ noecho();
+ struct more_file ret = more_open(filename);
+ if (ret.f == NULL) {
+ return *mf;
+ }
+
+ more_close(mf);
+ more_refresh(&ret);
+ return ret;
+}
+
static int more(const char *path)
{
struct more_file mf = more_open(path);
@@ -85,7 +108,7 @@ static int more(const char *path)
return 1;
}
- man_refresh(&mf);
+ more_refresh(&mf);
int count = 0;
while (mf.f) {
@@ -106,7 +129,7 @@ static int more(const char *path)
if (count == 0) {
count = LINES - 1;
}
- man_scroll(&mf, count, 1);
+ more_scroll(&mf, count, 1);
break;
case 'b':
@@ -114,7 +137,7 @@ static int more(const char *path)
if (count == 0) {
count = LINES - 1;
}
- man_scroll(&mf, count, -1);
+ more_scroll(&mf, count, -1);
break;
case ' ':
@@ -122,26 +145,26 @@ static int more(const char *path)
/* FALLTHRU */
case 'j':
case '\n':
- man_scroll(&mf, count, 1);
+ more_scroll(&mf, count, 1);
break;
case 'k':
- man_scroll(&mf, count, -1);
+ more_scroll(&mf, count, -1);
break;
case 'd':
case CTRL_D:
- man_scroll(&mf, count, (LINES - 1) / 2);
+ more_scroll(&mf, count, (LINES - 1) / 2);
break;
case 's':
count = count ? count : 1;
- man_scroll(&mf, LINES - 1 + count, 1);
+ more_scroll(&mf, LINES - 1 + count, 1);
break;
case 'u':
case CTRL_U:
- man_scroll(&mf, count, -(LINES - 1) / 2);
+ more_scroll(&mf, count, -(LINES - 1) / 2);
break;
case 'G':
@@ -150,7 +173,7 @@ static int more(const char *path)
}
/* FALLTHRU */
case 'g':
- man_scroll(&mf, count - mf.topline, 1);
+ more_scroll(&mf, count - mf.topline, 1);
break;
case 'R':
@@ -158,7 +181,7 @@ static int more(const char *path)
/* FALLTHRU */
case 'r':
case CTRL_L:
- man_refresh(&mf);
+ more_refresh(&mf);
break;
case 'm':
@@ -195,7 +218,7 @@ static int more(const char *path)
switch (c2) {
case 'e':
- // examine();
+ mf = more_examine(&mf);
break;
case 'n':
@@ -350,9 +373,8 @@ static void more_exit(void)
int main(int argc, char *argv[])
{
- int c;
+ setlocale(LC_ALL, "");
- int clear = 0;
int fastexit = 0;
int ignorecase = 0;
int compressempty = 0;
@@ -360,10 +382,11 @@ int main(int argc, char *argv[])
adjust_args(&argc, &argv);
+ int c;
while ((c = getopt(argc, argv, "ceisun:p:t:")) != -1) {
switch (c) {
case 'c':
- clear = 1;
+ more_clear = 1;
break;
case 'e':
@@ -419,7 +442,7 @@ int main(int argc, char *argv[])
atexit(more_exit);
- if (clear) {
+ if (more_clear) {
clear();
}