podman
1//go:build windows
2
3package terminal
4
5import (
6"github.com/sirupsen/logrus"
7"golang.org/x/sys/windows"
8)
9
10// SetConsole switches the windows terminal mode to be able to handle colors, etc
11func SetConsole() error {
12if err := setConsoleMode(windows.Stdout, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err != nil {
13return err
14}
15if err := setConsoleMode(windows.Stderr, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err != nil {
16return err
17}
18if err := setConsoleMode(windows.Stdin, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err != nil {
19return err
20}
21return nil
22}
23
24func setConsoleMode(handle windows.Handle, flags uint32) error {
25var mode uint32
26err := windows.GetConsoleMode(handle, &mode)
27if err != nil {
28//nolint:nilerr
29return nil // not a terminal
30}
31if err := windows.SetConsoleMode(handle, mode|flags); err != nil {
32// In similar code, it is not considered an error if we cannot set the
33// console mode. Following same line of thinking here.
34logrus.WithError(err).Debug("Failed to set console mode for cli")
35}
36
37return nil
38}
39