mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Use all console mode constants from go-ansiterm
The missing console mode constants were added to go-ansiterm in Azure/go-ansiterm#23. Use these constants instead of defining them locally. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
This commit is contained in:
parent
2b946fbc70
commit
9335683fa5
1 changed files with 12 additions and 19 deletions
|
@ -23,14 +23,7 @@ type Winsize struct {
|
||||||
Width uint16
|
Width uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
// vtInputSupported is true if winterm.ENABLE_VIRTUAL_TERMINAL_INPUT is supported by the console
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx
|
|
||||||
enableVirtualTerminalInput = 0x0200
|
|
||||||
enableVirtualTerminalProcessing = 0x0004
|
|
||||||
disableNewlineAutoReturn = 0x0008
|
|
||||||
)
|
|
||||||
|
|
||||||
// vtInputSupported is true if enableVirtualTerminalInput is supported by the console
|
|
||||||
var vtInputSupported bool
|
var vtInputSupported bool
|
||||||
|
|
||||||
// StdStreams returns the standard streams (stdin, stdout, stderr).
|
// StdStreams returns the standard streams (stdin, stdout, stderr).
|
||||||
|
@ -40,8 +33,8 @@ func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|
||||||
var emulateStdin, emulateStdout, emulateStderr bool
|
var emulateStdin, emulateStdout, emulateStderr bool
|
||||||
fd := os.Stdin.Fd()
|
fd := os.Stdin.Fd()
|
||||||
if mode, err := winterm.GetConsoleMode(fd); err == nil {
|
if mode, err := winterm.GetConsoleMode(fd); err == nil {
|
||||||
// Validate that enableVirtualTerminalInput is supported, but do not set it.
|
// Validate that winterm.ENABLE_VIRTUAL_TERMINAL_INPUT is supported, but do not set it.
|
||||||
if err = winterm.SetConsoleMode(fd, mode|enableVirtualTerminalInput); err != nil {
|
if err = winterm.SetConsoleMode(fd, mode|winterm.ENABLE_VIRTUAL_TERMINAL_INPUT); err != nil {
|
||||||
emulateStdin = true
|
emulateStdin = true
|
||||||
} else {
|
} else {
|
||||||
vtInputSupported = true
|
vtInputSupported = true
|
||||||
|
@ -53,21 +46,21 @@ func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|
||||||
|
|
||||||
fd = os.Stdout.Fd()
|
fd = os.Stdout.Fd()
|
||||||
if mode, err := winterm.GetConsoleMode(fd); err == nil {
|
if mode, err := winterm.GetConsoleMode(fd); err == nil {
|
||||||
// Validate disableNewlineAutoReturn is supported, but do not set it.
|
// Validate winterm.DISABLE_NEWLINE_AUTO_RETURN is supported, but do not set it.
|
||||||
if err = winterm.SetConsoleMode(fd, mode|enableVirtualTerminalProcessing|disableNewlineAutoReturn); err != nil {
|
if err = winterm.SetConsoleMode(fd, mode|winterm.ENABLE_VIRTUAL_TERMINAL_PROCESSING|winterm.DISABLE_NEWLINE_AUTO_RETURN); err != nil {
|
||||||
emulateStdout = true
|
emulateStdout = true
|
||||||
} else {
|
} else {
|
||||||
winterm.SetConsoleMode(fd, mode|enableVirtualTerminalProcessing)
|
winterm.SetConsoleMode(fd, mode|winterm.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = os.Stderr.Fd()
|
fd = os.Stderr.Fd()
|
||||||
if mode, err := winterm.GetConsoleMode(fd); err == nil {
|
if mode, err := winterm.GetConsoleMode(fd); err == nil {
|
||||||
// Validate disableNewlineAutoReturn is supported, but do not set it.
|
// Validate winterm.DISABLE_NEWLINE_AUTO_RETURN is supported, but do not set it.
|
||||||
if err = winterm.SetConsoleMode(fd, mode|enableVirtualTerminalProcessing|disableNewlineAutoReturn); err != nil {
|
if err = winterm.SetConsoleMode(fd, mode|winterm.ENABLE_VIRTUAL_TERMINAL_PROCESSING|winterm.DISABLE_NEWLINE_AUTO_RETURN); err != nil {
|
||||||
emulateStderr = true
|
emulateStderr = true
|
||||||
} else {
|
} else {
|
||||||
winterm.SetConsoleMode(fd, mode|enableVirtualTerminalProcessing)
|
winterm.SetConsoleMode(fd, mode|winterm.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,9 +176,9 @@ func SetRawTerminalOutput(fd uintptr) (*State, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore failures, since disableNewlineAutoReturn might not be supported on this
|
// Ignore failures, since winterm.DISABLE_NEWLINE_AUTO_RETURN might not be supported on this
|
||||||
// version of Windows.
|
// version of Windows.
|
||||||
winterm.SetConsoleMode(fd, state.mode|disableNewlineAutoReturn)
|
winterm.SetConsoleMode(fd, state.mode|winterm.DISABLE_NEWLINE_AUTO_RETURN)
|
||||||
return state, err
|
return state, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +208,7 @@ func MakeRaw(fd uintptr) (*State, error) {
|
||||||
mode |= winterm.ENABLE_INSERT_MODE
|
mode |= winterm.ENABLE_INSERT_MODE
|
||||||
mode |= winterm.ENABLE_QUICK_EDIT_MODE
|
mode |= winterm.ENABLE_QUICK_EDIT_MODE
|
||||||
if vtInputSupported {
|
if vtInputSupported {
|
||||||
mode |= enableVirtualTerminalInput
|
mode |= winterm.ENABLE_VIRTUAL_TERMINAL_INPUT
|
||||||
}
|
}
|
||||||
|
|
||||||
err = winterm.SetConsoleMode(fd, mode)
|
err = winterm.SetConsoleMode(fd, mode)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue