terminal: do not use escape codes on windows unless they are supported

This commit is contained in:
Alex Brainman
2016-03-09 15:20:03 +11:00
committed by aarzilli
parent e88ea83e1d
commit ff0ec8ce00
3 changed files with 45 additions and 1 deletions

View File

@ -42,7 +42,7 @@ func New(client service.Client, conf *config.Config) *Term {
line: liner.NewLiner(),
client: client,
cmds: cmds,
dumb: strings.ToLower(os.Getenv("TERM")) == "dumb",
dumb: !supportsEscapeCodes(),
}
}

View File

@ -0,0 +1,13 @@
// +build !windows
package terminal
import (
"os"
"strings"
)
// supportsEscapeCodes returns true if console handles escape codes.
func supportsEscapeCodes() bool {
return strings.ToLower(os.Getenv("TERM")) != "dumb"
}

View File

@ -0,0 +1,31 @@
package terminal
import (
"os"
"strings"
"syscall"
)
// supportsEscapeCodes returns true if console handles escape codes.
func supportsEscapeCodes() bool {
if strings.ToLower(os.Getenv("TERM")) == "dumb" {
return false
}
if strings.ToLower(os.Getenv("ConEmuANSI")) == "on" {
// The ConEmu terminal is installed. Use it.
return true
}
const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
h, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
if err != nil {
return false
}
var m uint32
err = syscall.GetConsoleMode(h, &m)
if err != nil {
return false
}
return m&ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0
}