Quellcode durchsuchen

Fix: fansi detects if the win console supports styling

default_compile_flags
vector-of-bool vor 3 Jahren
Ursprung
Commit
2376aa6f99
2 geänderte Dateien mit 14 neuen und 2 gelöschten Zeilen
  1. +0
    -1
      src/dds/util/output.win.cpp
  2. +14
    -1
      src/fansi/styled.cpp

+ 0
- 1
src/dds/util/output.win.cpp Datei anzeigen

@@ -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 Datei anzeigen

@@ -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); }

Laden…
Abbrechen
Speichern