diff --git a/.github/workflows/win.yml b/.github/workflows/win.yml index 9cd1eae3e809..0890978d334c 100644 --- a/.github/workflows/win.yml +++ b/.github/workflows/win.yml @@ -278,7 +278,6 @@ jobs: echo "CRYSTAL_LIBRARY_PATH=$(pwd)\libs" >> ${env:GITHUB_ENV} echo 'CRYSTAL_CONFIG_PATH=$ORIGIN\src' >> ${env:GITHUB_ENV} echo 'CRYSTAL_CONFIG_LIBRARY_PATH=$ORIGIN\lib' >> ${env:GITHUB_ENV} - echo "TERM=dumb" >> ${env:GITHUB_ENV} echo "LLVM_CONFIG=$(pwd)\llvm\bin\llvm-config.exe" >> ${env:GITHUB_ENV} echo "CRYSTAL_CONFIG_BUILD_COMMIT=$(git rev-parse --short=9 HEAD)" >> ${env:GITHUB_ENV} echo "SOURCE_DATE_EPOCH=$(Get-Date -Millisecond 0 -UFormat %s)" >> ${env:GITHUB_ENV} diff --git a/src/crystal/system/win32/file_descriptor.cr b/src/crystal/system/win32/file_descriptor.cr index cc9ee508c2be..d9013bb90bc2 100644 --- a/src/crystal/system/win32/file_descriptor.cr +++ b/src/crystal/system/win32/file_descriptor.cr @@ -170,8 +170,14 @@ module Crystal::System::FileDescriptor console_handle = false handle = LibC._get_osfhandle(fd) if handle != -1 - if LibC.GetConsoleMode(LibC::HANDLE.new(handle), out _) != 0 + handle = LibC::HANDLE.new(handle) + if LibC.GetConsoleMode(handle, out old_mode) != 0 console_handle = true + if fd == 1 || fd == 2 # STDOUT or STDERR + if LibC.SetConsoleMode(handle, old_mode | LibC::ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0 + at_exit { LibC.SetConsoleMode(handle, old_mode) } + end + end end end diff --git a/src/lib_c/x86_64-windows-msvc/c/consoleapi.cr b/src/lib_c/x86_64-windows-msvc/c/consoleapi.cr index 8eb8467eb3c5..90693df681ce 100644 --- a/src/lib_c/x86_64-windows-msvc/c/consoleapi.cr +++ b/src/lib_c/x86_64-windows-msvc/c/consoleapi.cr @@ -1,7 +1,10 @@ require "c/winnt" lib LibC + ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004 + fun GetConsoleMode(hConsoleHandle : HANDLE, lpMode : DWORD*) : BOOL + fun SetConsoleMode(hConsoleHandle : HANDLE, dwMode : DWORD) : BOOL fun GetConsoleCP : DWORD fun GetConsoleOutputCP : DWORD