From e8107b1889a620b6ba446953e698b30f1803b2cb Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Tue, 23 May 2017 15:16:27 +0200 Subject: mshow: spawn a pager for interactive use --- mshow.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'mshow.c') diff --git a/mshow.c b/mshow.c index 4c62410..a96d540 100644 --- a/mshow.c +++ b/mshow.c @@ -703,6 +703,8 @@ done: int main(int argc, char *argv[]) { + pid_t pid1 = -1, pid2 = -1; + int c; while ((c = getopt(argc, argv, "h:A:qrtHLx:O:Rn")) != -1) switch(c) { @@ -731,6 +733,22 @@ main(int argc, char *argv[]) if (!rflag && !Oflag && !Rflag) safe_output = 1; + if (safe_output && isatty(1)) { + char *pg; + pg = getenv("MBLAZE_PAGER"); + if (!pg) + pg = getenv("PAGER"); + if (pg && *pg && strcmp(pg, "cat") != 0) { + pid2 = pipeto(pg); + if (pid2 < 0) + fprintf(stderr, + "mshow: spawning pager '%s': %s\n", + pg, strerror(errno)); + else if (!getenv("MBLAZE_NOCOLOR")) + pid1 = pipeto("mcolor"); // ignore error + } + } + if (xflag) { // extract extract(xflag, argc-optind, argv+optind, 0); } else if (Oflag) { // extract to stdout @@ -758,5 +776,10 @@ main(int argc, char *argv[]) blaze822_seq_setcur(newcur); } + if (pid2 > 0) + pipeclose(pid2); + if (pid1 > 0) + pipeclose(pid1); + return 0; } -- cgit 1.4.1