commit 25d459aa64c137f40f45d935d6b235fb6d82b435
parent 2d90cf324e0a6aeffe326d0d817d993cae72e053
Author: Chris Allegretta <chrisa@asty.org>
Date: Fri, 30 Jan 2009 08:34:27 +0000
2009-01-29 Chris Allegretta <chrisa@asty.org>
* nano.c (main): Add support for nano acting like a pager when invoked with - as first
file argument. Not yet perfect (garbles screen state on exit) but it's something.
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4356 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
3 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,7 @@
+2009-01-29 Chris Allegretta <chrisa@asty.org>
+ * nano.c (main): Add support for nano acting like a pager when invoked with - as first
+ file argument. Not yet perfect (garbles screen state on exit) but it's something.
+
2009-01-28 Davide Pesavento <davidepesa@gmail.com>
* doc/syntax/gentoo.nanorc: Updates from David and Mike Frysinger.
diff --git a/src/color.c b/src/color.c
@@ -260,6 +260,9 @@ void reset_multis(filestruct *fileptr)
int i;
filestruct *oof;
+ if (!openfile->syntax)
+ return;
+
for (i = 0; i < openfile->syntax->nmultis; i++) {
for (oof = fileptr->next; oof != NULL; oof = oof->next) {
if (oof->multiswatching == NULL)
diff --git a/src/nano.c b/src/nano.c
@@ -2239,6 +2239,30 @@ int main(int argc, char **argv)
optind++;
}
+ if (optind < argc && !strcmp(argv[optind], "-")) {
+ FILE *f;
+ int ttystdin;
+ struct termios term;
+
+ enable_signals();
+ open_buffer("", FALSE);
+ endwin();
+
+ f = fopen("/dev/stdin", "rb");
+ if (f == NULL)
+ nperror("fopen");
+
+ read_file(f, "stdin", TRUE);
+ ttystdin = open("/dev/tty", O_RDONLY);
+ if (!ttystdin)
+ die(_("Couldn't reopen stdin from keyboard, sorry\n"));
+
+ dup2(ttystdin,0);
+ close(ttystdin);
+ set_modified();
+ optind++;
+ }
+
#ifdef ENABLE_MULTIBUFFER
old_multibuffer = ISSET(MULTIBUFFER);
SET(MULTIBUFFER);