summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-06-29 12:43:20 -0400
committerGitHub <noreply@github.com>2020-06-29 12:43:20 -0400
commitc682ca3d35a3e4f9265e10dc9898cbe3ac3d35a2 (patch)
tree9ccceb17b10298a4389b0f7963d8c09bcf625e56 /pkg
parentd90e8b6873f3f06a1b2cfe9f55ac61b3e5904bc3 (diff)
parentdfb2f92583a5797b1ee8cdf29399dc29b7f3c6d3 (diff)
downloadpodman-c682ca3d35a3e4f9265e10dc9898cbe3ac3d35a2.tar.gz
podman-c682ca3d35a3e4f9265e10dc9898cbe3ac3d35a2.tar.bz2
podman-c682ca3d35a3e4f9265e10dc9898cbe3ac3d35a2.zip
Merge pull request #6794 from baude/v2remotewindowsterminal
Set console mode for windows
Diffstat (limited to 'pkg')
-rw-r--r--pkg/terminal/console_unix.go8
-rw-r--r--pkg/terminal/console_windows.go37
2 files changed, 45 insertions, 0 deletions
diff --git a/pkg/terminal/console_unix.go b/pkg/terminal/console_unix.go
new file mode 100644
index 000000000..6eee6aa2f
--- /dev/null
+++ b/pkg/terminal/console_unix.go
@@ -0,0 +1,8 @@
+// +build !windows
+
+package terminal
+
+// SetConsole for non-windows environments is a no-op
+func SetConsole() error {
+ return nil
+}
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
+}