File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -113,6 +113,8 @@ enum class control { // Behaviour of rang function calls
113113 Force = 2 // force ansi color output to non terminal streams
114114};
115115// Use rang::setControlMode to set rang control mode
116+ // The default can be set by environment variables: https://bixense.com/clicolors/
117+ // NO_COLOR to disable color output, CLICOLOR_FORCE to force color output
116118
117119enum class winTerm { // Windows Terminal Mode
118120 Auto = 0 , // (Default) automatically detects wheter Ansi or Native API
@@ -126,7 +128,7 @@ namespace rang_implementation {
126128
127129 inline std::atomic<control> &controlMode () noexcept
128130 {
129- static std::atomic<control> value (control::Auto );
131+ static std::atomic<control> value (defaultControlMode () );
130132 return value;
131133 }
132134
@@ -136,6 +138,18 @@ namespace rang_implementation {
136138 return termMode;
137139 }
138140
141+ // https://bixense.com/clicolors/
142+ inline control defaultControlMode () noexcept
143+ {
144+ if (std::getenv (" NO_COLOR" ) != nullptr ) {
145+ return control::Off;
146+ }
147+ if (std::getenv (" CLICOLOR_FORCE" ) != nullptr ) {
148+ return control::Force;
149+ }
150+ return control::Auto;
151+ }
152+
139153 inline bool supportsColor () noexcept
140154 {
141155#if defined(OS_LINUX) || defined(OS_MAC)
You can’t perform that action at this time.
0 commit comments