Skip to content

Enable VT100 Sequences on Windows #2350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Sources/TSCBasic/TerminalController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/

import TSCLibc
#if os(Windows)
import MSVCRT
#endif

/// A class to have better control on tty output streams: standard output and standard error.
/// Allows operations like cursor movement and colored text output on tty.
Expand Down Expand Up @@ -84,6 +87,18 @@ public final class TerminalController {
} else {
width = 80
}

#if os(Windows)
// Enable VT100 interpretation
let hOut = GetStdHandle(STD_OUTPUT_HANDLE)
var dwMode: DWORD = 0

guard hOut != INVALID_HANDLE_VALUE else { return nil }
guard GetConsoleMode(hOut, &dwMode) else { return nil }

dwMode |= DWORD(ENABLE_VIRTUAL_TERMINAL_PROCESSING)
guard SetConsoleMode(hOut, dwMode) else { return nil }
#endif
self.stream = stream
}

Expand Down