yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
ansi_style.cc
Go to the documentation of this file.
2
3#include <cstdlib>
4#include <cstring>
5
6#ifdef _WIN32
7#include <io.h>
8#else
9#include <unistd.h>
10#endif
11
12namespace yaze::cli::util {
13namespace {
14
15bool IsTerminal(std::FILE* stream) {
16#ifdef _WIN32
17 return _isatty(_fileno(stream)) != 0;
18#else
19 return isatty(fileno(stream)) != 0;
20#endif
21}
22
23} // namespace
24
25AnsiStyle AnsiStyle::ForStream(std::FILE* stream) {
26 const char* no_color = std::getenv("NO_COLOR");
27 if (no_color != nullptr && no_color[0] != '\0') {
28 return AnsiStyle(false);
29 }
30 const char* term = std::getenv("TERM");
31 if (term != nullptr && std::strcmp(term, "dumb") == 0) {
32 return AnsiStyle(false);
33 }
34 return AnsiStyle(stream != nullptr && IsTerminal(stream));
35}
36
37} // namespace yaze::cli::util
static AnsiStyle ForStream(std::FILE *stream)
Definition ansi_style.cc:25
constexpr AnsiStyle(bool enabled)
Definition ansi_style.h:14