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

@@ -21,7 +21,6 @@ void dds::enable_ansi_console() 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);
if (stdio_console == INVALID_HANDLE_VALUE) {
return false;

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

@@ -16,7 +16,20 @@
#include <vector>

#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
#include <unistd.h>
bool fansi::detect_should_style() noexcept { return ::isatty(STDOUT_FILENO); }

Loading…
Cancel
Save