瀏覽代碼

Fix: fansi detects if the win console supports styling

default_compile_flags
vector-of-bool 3 年之前
父節點
當前提交
2376aa6f99
共有 2 個檔案被更改,包括 14 行新增2 行删除
  1. +0
    -1
      src/dds/util/output.win.cpp
  2. +14
    -1
      src/fansi/styled.cpp

+ 0
- 1
src/dds/util/output.win.cpp 查看文件

@@ -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 查看文件

@@ -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…
取消
儲存