Skip to content

Commit c7ed328

Browse files
authored
Enable virtual terminal processing on Windows (microsoft#511)
1 parent e783fa3 commit c7ed328

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

cmd/tsgo/enablevtprocessing_other.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build !windows
2+
3+
package main
4+
5+
func enableVirtualTerminalProcessing() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"golang.org/x/sys/windows"
5+
)
6+
7+
func enableVirtualTerminalProcessing() {
8+
hStdout, err := windows.GetStdHandle(windows.STD_OUTPUT_HANDLE)
9+
if err == nil && hStdout != windows.InvalidHandle {
10+
var mode uint32
11+
err = windows.GetConsoleMode(windows.Handle(hStdout), &mode)
12+
if err == nil {
13+
windows.SetConsoleMode(windows.Handle(hStdout), mode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
14+
}
15+
}
16+
}

cmd/tsgo/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ func parseArgs() *cliOptions {
121121
}
122122

123123
func main() {
124+
// TypeScript uses ANSI escape sequences which cmd.exe won't parse without enabling virtual terminal processing.
125+
enableVirtualTerminalProcessing()
126+
124127
if args := os.Args[1:]; len(args) > 0 {
125128
switch args[0] {
126129
case "tsc":

0 commit comments

Comments
 (0)