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.
pull/244/head
Leah Neukirchen 10 months ago
parent 23a9e7022e
commit 43f2cb8b49

@ -575,9 +575,13 @@ main(int argc, char *argv[])
struct winsize w; struct winsize w;
int ttyfd = open("/dev/tty", O_RDONLY | O_NOCTTY); int ttyfd = open("/dev/tty", O_RDONLY | O_NOCTTY);
if (ttyfd >= 0 && ioctl(ttyfd, TIOCGWINSZ, &w) == 0) { if (ttyfd >= 0) {
cols = w.ws_col; if (ioctl(ttyfd, TIOCGWINSZ, &w) == 0)
cols = w.ws_col;
close(ttyfd);
}
if (isatty(1)) {
char *pg; char *pg;
pg = getenv("MBLAZE_PAGER"); pg = getenv("MBLAZE_PAGER");
if (!pg) if (!pg)
@ -590,8 +594,6 @@ main(int argc, char *argv[])
pg, strerror(errno)); pg, strerror(errno));
} }
} }
if (ttyfd >= 0)
close(ttyfd);
xpledge("stdio rpath", ""); xpledge("stdio rpath", "");

Loading…
Cancel
Save