Browse Source

Fix: fansi detects if the win console supports styling

default_compile_flags
vector-of-bool 3 years ago
parent
commit
2376aa6f99
2 changed files with 14 additions and 2 deletions
  1. +0
    -1
      src/dds/util/output.win.cpp
  2. +14
    -1
      src/fansi/styled.cpp

+ 0
- 1
src/dds/util/output.win.cpp View File

} }


bool dds::stdout_is_a_tty() noexcept { bool dds::stdout_is_a_tty() noexcept {
// XXX: Newer Windows consoles support ANSI color, so this should be made smarter
auto stdio_console = ::GetStdHandle(STD_OUTPUT_HANDLE); auto stdio_console = ::GetStdHandle(STD_OUTPUT_HANDLE);
if (stdio_console == INVALID_HANDLE_VALUE) { if (stdio_console == INVALID_HANDLE_VALUE) {
return false; return false;

+ 14
- 1
src/fansi/styled.cpp View File

#include <vector> #include <vector>


#if NEO_OS_IS_WINDOWS #if NEO_OS_IS_WINDOWS
bool fansi::detect_should_style() noexcept { return false; }
#include <windows.h>

bool fansi::detect_should_style() noexcept {
auto stdio_console = ::GetStdHandle(STD_OUTPUT_HANDLE);
if (stdio_console == INVALID_HANDLE_VALUE) {
return false;
}
DWORD mode = 0;
if (!::GetConsoleMode(stdio_console, &mode)) {
// Failed to get the mode
return false;
}
return (mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING);
}
#else #else
#include <unistd.h> #include <unistd.h>
bool fansi::detect_should_style() noexcept { return ::isatty(STDOUT_FILENO); } bool fansi::detect_should_style() noexcept { return ::isatty(STDOUT_FILENO); }

Loading…
Cancel
Save