MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / IsColorTerminal

Function IsColorTerminal

deps/google-benchmark/src/colorprint.cc:158–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156}
157
158bool IsColorTerminal() {
159#if BENCHMARK_OS_WINDOWS
160 // On Windows the TERM variable is usually not set, but the
161 // console there does support colors.
162 return 0 != _isatty(_fileno(stdout));
163#else
164 // On non-Windows platforms, we rely on the TERM variable. This list of
165 // supported TERM values is copied from Google Test:
166 // <https://github.com/google/googletest/blob/master/googletest/src/gtest.cc#L2925>.
167 const char* const SUPPORTED_TERM_VALUES[] = {
168 "xterm", "xterm-color", "xterm-256color",
169 "screen", "screen-256color", "tmux",
170 "tmux-256color", "rxvt-unicode", "rxvt-unicode-256color",
171 "linux", "cygwin",
172 };
173
174 const char* const term = getenv("TERM");
175
176 bool term_supports_color = false;
177 for (const char* candidate : SUPPORTED_TERM_VALUES) {
178 if (term && 0 == strcmp(term, candidate)) {
179 term_supports_color = true;
180 break;
181 }
182 }
183
184 return 0 != isatty(fileno(stdout)) && term_supports_color;
185#endif // BENCHMARK_OS_WINDOWS
186}
187
188} // end namespace benchmark

Callers 1

GetOutputOptionsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected