summary refs log tree commit diff
path: root/bin/hilex.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-01-19 20:54:06 -0500
committerJune McEnroe <june@causal.agency>2021-01-19 20:54:06 -0500
commit399db92745bcbaa8a9345eed26848d39dc3ea220 (patch)
tree15cb5030d879b9b86f022fe0fe6e90a0f3fb665c /bin/hilex.c
parentSupport BSD make syntax and match *.am (diff)
downloadsrc-399db92745bcbaa8a9345eed26848d39dc3ea220.tar.gz
src-399db92745bcbaa8a9345eed26848d39dc3ea220.zip
Don't use a pager if reading standard input
Diffstat (limited to 'bin/hilex.c')
-rw-r--r--bin/hilex.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/bin/hilex.c b/bin/hilex.c
index 93401d95..59c1f12d 100644
--- a/bin/hilex.c
+++ b/bin/hilex.c
@@ -121,10 +121,10 @@ enum Option {
 typedef void Header(const char *opts[]);
 typedef void Output(const char *opts[], enum Class class, const char *text);
 
-static bool tty;
+static bool pager;
 static void ansiHeader(const char *opts[]) {
 	(void)opts;
-	if (!(tty = isatty(STDOUT_FILENO))) return;
+	if (!pager) return;
 	const char *shell = getenv("SHELL");
 	const char *pager = getenv("PAGER");
 	if (!shell) shell = "/bin/sh";
@@ -152,7 +152,7 @@ static void ansiHeader(const char *opts[]) {
 
 static void ansiFooter(const char *opts[]) {
 	(void)opts;
-	if (!tty) return;
+	if (!pager) return;
 	int status;
 	fclose(stdout);
 	wait(&status);
@@ -365,6 +365,7 @@ int main(int argc, char *argv[]) {
 		path = argv[optind];
 		file = fopen(path, "r");
 		if (!file) err(EX_NOINPUT, "%s", path);
+		pager = isatty(STDOUT_FILENO);
 	}
 
 	if (!name) {