| 190 | bool g_use_color = false; |
| 191 | |
| 192 | void init_console_color() { |
| 193 | #ifdef _WIN32 |
| 194 | HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); |
| 195 | DWORD mode = 0; |
| 196 | if (h != INVALID_HANDLE_VALUE && GetConsoleMode(h, &mode)) |
| 197 | SetConsoleMode(h, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); |
| 198 | const bool tty = _isatty(_fileno(stdout)) != 0; |
| 199 | #else |
| 200 | const bool tty = isatty(fileno(stdout)) != 0; |
| 201 | #endif |
| 202 | g_use_color = tty && std::getenv("NO_COLOR") == nullptr; |
| 203 | } |
| 204 | |
| 205 | template <typename... A> |
| 206 | void cprint(const fmt::text_style& st, fmt::format_string<A...> f, A&&... a) { |