summaryrefslogtreecommitdiff
path: root/pkg/terminal/console_windows.go
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-06-26 16:22:04 -0500
committerBrent Baude <bbaude@redhat.com>2020-06-29 09:17:55 -0500
commitdfb2f92583a5797b1ee8cdf29399dc29b7f3c6d3 (patch)
treeec6c2dbb56530638989a318321a264e39b21c2b5 /pkg/terminal/console_windows.go
parent771c887010709cdf718be252ca91a852c6735da7 (diff)
downloadpodman-dfb2f92583a5797b1ee8cdf29399dc29b7f3c6d3.tar.gz
podman-dfb2f92583a5797b1ee8cdf29399dc29b7f3c6d3.tar.bz2
podman-dfb2f92583a5797b1ee8cdf29399dc29b7f3c6d3.zip
Set console mode for windows
Windows terminal handling is different than darwin and linux. It needs to have the terminal mode set to enable virtual terminal processing. This allows colors and other things to work. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/terminal/console_windows.go')
-rw-r--r--pkg/terminal/console_windows.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/pkg/terminal/console_windows.go b/pkg/terminal/console_windows.go
new file mode 100644
index 000000000..c7691857c
--- /dev/null
+++ b/pkg/terminal/console_windows.go
@@ -0,0 +1,37 @@
+// +build windows
+
+package terminal
+
+import (
+ "github.com/sirupsen/logrus"
+ "golang.org/x/sys/windows"
+)
+
+// SetConsole switches the windows terminal mode to be able to handle colors, etc
+func SetConsole() error {
+ if err := setConsoleMode(windows.Stdout, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err != nil {
+ return err
+ }
+ if err := setConsoleMode(windows.Stderr, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err != nil {
+ return err
+ }
+ if err := setConsoleMode(windows.Stdin, windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err != nil {
+ return err
+ }
+ return nil
+}
+
+func setConsoleMode(handle windows.Handle, flags uint32) error {
+ var mode uint32
+ err := windows.GetConsoleMode(handle, &mode)
+ if err != nil {
+ return err
+ }
+ if err := windows.SetConsoleMode(handle, mode|flags); err != nil {
+ // In similar code, it is not considered an error if we cannot set the
+ // console mode. Following same line of thinking here.
+ logrus.WithError(err).Error("Failed to set console mode for cli")
+ }
+
+ return nil
+}