From 49768a38a7662dab13f2e6efa9561fbdcb06d83c Mon Sep 17 00:00:00 2001 From: Shav Kinderlehrer Date: Thu, 10 Aug 2023 11:50:57 -0400 Subject: Add NO_COLOR support --- source/style/package.d | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source/style') diff --git a/source/style/package.d b/source/style/package.d index 2e5ff7f..1c55a99 100644 --- a/source/style/package.d +++ b/source/style/package.d @@ -1,15 +1,22 @@ module style; import std.conv; +import core.stdc.stdlib : getenv; import style.color; string set(string s, int code) { + if (getenv("NO_COLOR")) + return s; + return ("%{\x1b[" ~ to!string(code) ~ "m%}") ~ s ~ ( "%{\x1b[" ~ to!string((Color.reset + 0)) ~ "m%}"); } string set(string s, int code, bool close) { + if (getenv("NO_COLOR")) + return s; + return ("%{\x1b[" ~ to!string(code) ~ "m%}") ~ s ~ (close ? ( "%{\x1b[" ~ to!string((Color.reset + 0)) ~ "m%}") : ""); } -- cgit v1.2.3