about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2023-07-18 14:02:52 +0200
committerLeah Neukirchen <leah@vuxu.org>2023-07-18 14:04:59 +0200
commit43f2cb8b491d95eb79b6b6d404865135971fe642 (patch)
treeeb6f3a0d272d22f2be5d5026c5796fcde98068fe
parent23a9e7022ea375aafc06ee28fd8466fccd0e5ded (diff)
downloadmblaze-43f2cb8b491d95eb79b6b6d404865135971fe642.tar.gz
mblaze-43f2cb8b491d95eb79b6b6d404865135971fe642.tar.xz
mblaze-43f2cb8b491d95eb79b6b6d404865135971fe642.zip
mscan: only spawn pager when stdout is a tty
We still get the terminal size for when users manually page, e.g.
mscan | less

This is consistent with how mshow already works.

Fixes #243.
-rw-r--r--mscan.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/mscan.c b/mscan.c
index 0494409..4052f1f 100644
--- a/mscan.c
+++ b/mscan.c
@@ -575,9 +575,13 @@ main(int argc, char *argv[])
 
 	struct winsize w;
 	int ttyfd = open("/dev/tty", O_RDONLY | O_NOCTTY);
-	if (ttyfd >= 0 && ioctl(ttyfd, TIOCGWINSZ, &w) == 0) {
-		cols = w.ws_col;
+	if (ttyfd >= 0) {
+		if (ioctl(ttyfd, TIOCGWINSZ, &w) == 0)
+			cols = w.ws_col;
+		close(ttyfd);
+	}
 
+	if (isatty(1)) {
 		char *pg;
 		pg = getenv("MBLAZE_PAGER");
 		if (!pg)
@@ -590,8 +594,6 @@ main(int argc, char *argv[])
 				    pg, strerror(errno));
 		}
 	}
-	if (ttyfd >= 0)
-		close(ttyfd);
 
 	xpledge("stdio rpath", "");