Windows: Native console disableNewlineAutoReturn

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2016-03-24 15:37:47 -07:00
parent b290cff825
commit 8df7e3df44

View file

@ -31,6 +31,7 @@ const (
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx
enableVirtualTerminalInput = 0x0200 enableVirtualTerminalInput = 0x0200
enableVirtualTerminalProcessing = 0x0004 enableVirtualTerminalProcessing = 0x0004
disableNewlineAutoReturn = 0x0008
) )
// usingNativeConsole is true if we are using the Windows native console // usingNativeConsole is true if we are using the Windows native console
@ -146,9 +147,15 @@ func probeNativeConsole(state State) error {
// enableNativeConsole turns on native console mode // enableNativeConsole turns on native console mode
func enableNativeConsole(state State) error { func enableNativeConsole(state State) error {
// First attempt both enableVirtualTerminalProcessing and disableNewlineAutoReturn
if err := winterm.SetConsoleMode(uintptr(state.outHandle),
state.outMode|(enableVirtualTerminalProcessing|disableNewlineAutoReturn)); err != nil {
// That may fail, so fallback to trying just enableVirtualTerminalProcessing
if err := winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode|enableVirtualTerminalProcessing); err != nil { if err := winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode|enableVirtualTerminalProcessing); err != nil {
return err return err
} }
}
if err := winterm.SetConsoleMode(uintptr(state.inHandle), state.inMode|enableVirtualTerminalInput); err != nil { if err := winterm.SetConsoleMode(uintptr(state.inHandle), state.inMode|enableVirtualTerminalInput); err != nil {
winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode) // restore out if we can winterm.SetConsoleMode(uintptr(state.outHandle), state.outMode) // restore out if we can