podman

Форк
0
/
console_windows.go 
38 строк · 1.0 Кб
1
//go:build windows
2

3
package terminal
4

5
import (
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
11
func SetConsole() error {
12
	if err := setConsoleMode(windows.Stdout, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err != nil {
13
		return err
14
	}
15
	if err := setConsoleMode(windows.Stderr, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err != nil {
16
		return err
17
	}
18
	if err := setConsoleMode(windows.Stdin, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err != nil {
19
		return err
20
	}
21
	return nil
22
}
23

24
func setConsoleMode(handle windows.Handle, flags uint32) error {
25
	var mode uint32
26
	err := windows.GetConsoleMode(handle, &mode)
27
	if err != nil {
28
		//nolint:nilerr
29
		return nil // not a terminal
30
	}
31
	if 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.
34
		logrus.WithError(err).Debug("Failed to set console mode for cli")
35
	}
36

37
	return nil
38
}
39

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.