|
@@ -1,7 +1,11 @@
|
|
|
// +build windows
|
|
|
-
|
|
|
package term
|
|
|
|
|
|
+import (
|
|
|
+ "github.com/docker/docker/pkg/term/winconsole"
|
|
|
+ "io"
|
|
|
+)
|
|
|
+
|
|
|
// State holds the console mode for the terminal.
|
|
|
type State struct {
|
|
|
mode uint32
|
|
@@ -18,8 +22,8 @@ type Winsize struct {
|
|
|
// GetWinsize gets the window size of the given terminal
|
|
|
func GetWinsize(fd uintptr) (*Winsize, error) {
|
|
|
ws := &Winsize{}
|
|
|
- var info *CONSOLE_SCREEN_BUFFER_INFO
|
|
|
- info, err := GetConsoleScreenBufferInfo(fd)
|
|
|
+ var info *winconsole.CONSOLE_SCREEN_BUFFER_INFO
|
|
|
+ info, err := winconsole.GetConsoleScreenBufferInfo(fd)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -41,19 +45,19 @@ func SetWinsize(fd uintptr, ws *Winsize) error {
|
|
|
|
|
|
// IsTerminal returns true if the given file descriptor is a terminal.
|
|
|
func IsTerminal(fd uintptr) bool {
|
|
|
- _, e := GetConsoleMode(fd)
|
|
|
+ _, e := winconsole.GetConsoleMode(fd)
|
|
|
return e == nil
|
|
|
}
|
|
|
|
|
|
// RestoreTerminal restores the terminal connected to the given file descriptor to a
|
|
|
// previous state.
|
|
|
func RestoreTerminal(fd uintptr, state *State) error {
|
|
|
- return SetConsoleMode(fd, state.mode)
|
|
|
+ return winconsole.SetConsoleMode(fd, state.mode)
|
|
|
}
|
|
|
|
|
|
// SaveState saves the state of the given console
|
|
|
func SaveState(fd uintptr) (*State, error) {
|
|
|
- mode, e := GetConsoleMode(fd)
|
|
|
+ mode, e := winconsole.GetConsoleMode(fd)
|
|
|
if e != nil {
|
|
|
return nil, e
|
|
|
}
|
|
@@ -63,9 +67,9 @@ func SaveState(fd uintptr) (*State, error) {
|
|
|
// DisableEcho disbales the echo for given file descriptor and returns previous state
|
|
|
// see http://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx for these flag settings
|
|
|
func DisableEcho(fd uintptr, state *State) error {
|
|
|
- state.mode &^= (ENABLE_ECHO_INPUT)
|
|
|
- state.mode |= (ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT)
|
|
|
- return SetConsoleMode(fd, state.mode)
|
|
|
+ state.mode &^= (winconsole.ENABLE_ECHO_INPUT)
|
|
|
+ state.mode |= (winconsole.ENABLE_PROCESSED_INPUT | winconsole.ENABLE_LINE_INPUT)
|
|
|
+ return winconsole.SetConsoleMode(fd, state.mode)
|
|
|
}
|
|
|
|
|
|
// SetRawTerminal puts the terminal connected to the given file descriptor into raw
|
|
@@ -96,9 +100,18 @@ func MakeRaw(fd uintptr) (*State, error) {
|
|
|
// When all are enabled, the application is said to be in "cooked" mode, which means that most of the processing is handled for the application.
|
|
|
// When all are disabled, the application is in "raw" mode, which means that input is unfiltered and any processing is left to the application.
|
|
|
state.mode = 0
|
|
|
- err = SetConsoleMode(fd, state.mode)
|
|
|
+ err = winconsole.SetConsoleMode(fd, state.mode)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
return state, nil
|
|
|
}
|
|
|
+
|
|
|
+// GetHandleInfo returns file descriptor and bool indicating whether the file is a terminal
|
|
|
+func GetHandleInfo(in interface{}) (uintptr, bool) {
|
|
|
+ return winconsole.GetHandleInfo(in)
|
|
|
+}
|
|
|
+
|
|
|
+func StdStreams() (stdOut io.Writer, stdErr io.Writer, stdIn io.ReadCloser) {
|
|
|
+ return winconsole.StdStreams()
|
|
|
+}
|