From d21cf0869ef064a6d6e607d1e103003b8c696b92 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Sun, 28 Jan 2024 22:58:33 +0100 Subject: [PATCH] Add true color detection --- premake.make | 2 +- src/utils.cpp | 6 ++++++ src/utils.hpp | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/premake.make b/premake.make index 0ba580e..971486e 100644 --- a/premake.make +++ b/premake.make @@ -1,7 +1,7 @@ LDLIBS := -lscerror -lm MAJOR := 1 -MINOR := 1 +MINOR := 2 PATCH := 0 GENERATELIBHEADER := 1 diff --git a/src/utils.cpp b/src/utils.cpp index 2c04ad8..34eba14 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -60,6 +60,12 @@ void term::progress(int prefixlen, *_out << ' ' << std::setw(3) << perc << '%'; } +bool term::has_truecolor() const { + char* tc = getenv("COLORTERM"); + std::string colorterm {tc ? tc : ""}; + return colorterm.size() > 0 && (colorterm == "truecolor" || colorterm == "24bit"); +} + // ------------------------------------------------------------------------ cursor_hider::cursor_hider(std::ostream* out) : _out {out} { diff --git a/src/utils.hpp b/src/utils.hpp index e9afd39..eced5ad 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -24,6 +24,8 @@ namespace sc { const std::string& prefix, double cur, double total) const; + + bool has_truecolor() const; }; class cursor_hider {