File: ansi_windows.go

package info (click to toggle)
golang-github-jedib0t-go-pretty 6.5.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,700 kB
  • sloc: makefile: 28; sh: 14
file content (30 lines) | stat: -rw-r--r-- 599 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//go:build windows
// +build windows

package text

import (
	"os"
	"sync"

	"golang.org/x/sys/windows"
)

var enableVTPMutex = sync.Mutex{}

func areANSICodesSupported() bool {
	enableVTPMutex.Lock()
	defer enableVTPMutex.Unlock()

	outHandle := windows.Handle(os.Stdout.Fd())
	var outMode uint32
	if err := windows.GetConsoleMode(outHandle, &outMode); err == nil {
		if outMode&windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 {
			return true
		}
		if err := windows.SetConsoleMode(outHandle, outMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err == nil {
			return true
		}
	}
	return false
}