mirror of https://github.com/containers/podman.git
Merge pull request #6794 from baude/v2remotewindowsterminal
Set console mode for windows
This commit is contained in:
commit
c682ca3d35
|
@ -16,7 +16,9 @@ import (
|
||||||
_ "github.com/containers/libpod/cmd/podman/system"
|
_ "github.com/containers/libpod/cmd/podman/system"
|
||||||
_ "github.com/containers/libpod/cmd/podman/volumes"
|
_ "github.com/containers/libpod/cmd/podman/volumes"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
|
"github.com/containers/libpod/pkg/terminal"
|
||||||
"github.com/containers/storage/pkg/reexec"
|
"github.com/containers/storage/pkg/reexec"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,6 +55,10 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := terminal.SetConsole(); err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
Execute()
|
Execute()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package terminal
|
||||||
|
|
||||||
|
// SetConsole for non-windows environments is a no-op
|
||||||
|
func SetConsole() error {
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue