aboutsummaryrefslogtreecommitdiffhomepage
path: root/main.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2023-05-28 09:59:54 +0200
committerlemon <lsof@mailbox.org>2023-05-28 10:14:21 +0200
commit9c440c027913a7e8f1a417bd93d98628e8f85df4 (patch)
treead52c830805fee76427122b5e640e47d6f3c3ec5 /main.c
parent6f7bea0cff2ecbca3427def8ead2c9ceec966b14 (diff)
check color output
Diffstat (limited to 'main.c')
-rw-r--r--main.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/main.c b/main.c
index 8f72dd9..2404fd5 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,7 @@
#include "common.h"
#include "parse.h"
#include <stdlib.h>
+#include <unistd.h>
struct option ccopt;
@@ -42,6 +43,16 @@ optparse(const char **file, const char **targ, char **args)
}
}
+static void
+detectcolor(void)
+{
+ const char *s;
+ if (!isatty(STDERR_FILENO)
+ || ((s = getenv("NO_COLOR")) && *s)
+ || ((s = getenv("TERM")) && !strcmp(s, "dumb")))
+ ccopt.nocolor = 1;
+}
+
int
main(int argc, char **argv)
{
@@ -49,6 +60,7 @@ main(int argc, char **argv)
const char *file, *targ;
atexit(flushstd);
+ detectcolor();
optparse(&file, &targ, argv);
if (!file) {
efmt("usage: %s [options] <file>\n", *argv);