1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Improvements to ANSI emulation in conemu

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2015-10-30 11:10:12 +03:00 committed by John Howard
parent 7d13f2fb7d
commit 506722bf9f
2 changed files with 38 additions and 2 deletions

View file

@ -40,8 +40,8 @@ var usingNativeConsole bool
func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) { func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
switch { switch {
case os.Getenv("ConEmuANSI") == "ON": case os.Getenv("ConEmuANSI") == "ON":
// The ConEmu shell emulates ANSI well by default. // The ConEmu terminal emulates ANSI on output streams well.
return os.Stdin, os.Stdout, os.Stderr return windows.ConEmuStreams()
case os.Getenv("MSYSTEM") != "": case os.Getenv("MSYSTEM") != "":
// MSYS (mingw) does not emulate ANSI well. // MSYS (mingw) does not emulate ANSI well.
return windows.ConsoleStreams() return windows.ConsoleStreams()

View file

@ -8,8 +8,44 @@ import (
"syscall" "syscall"
"github.com/Azure/go-ansiterm/winterm" "github.com/Azure/go-ansiterm/winterm"
ansiterm "github.com/Azure/go-ansiterm"
"github.com/Sirupsen/logrus"
"io/ioutil"
) )
// ConEmuStreams returns prepared versions of console streams,
// for proper use in ConEmu terminal.
// The ConEmu terminal emulates ANSI on output streams well by default.
func ConEmuStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
if IsConsole(os.Stdin.Fd()) {
stdIn = newAnsiReader(syscall.STD_INPUT_HANDLE)
} else {
stdIn = os.Stdin
}
stdOut = os.Stdout
stdErr = os.Stderr
// WARNING (BEGIN): sourced from newAnsiWriter
logFile := ioutil.Discard
if isDebugEnv := os.Getenv(ansiterm.LogEnv); isDebugEnv == "1" {
logFile, _ = os.Create("ansiReaderWriter.log")
}
logger = &logrus.Logger{
Out: logFile,
Formatter: new(logrus.TextFormatter),
Level: logrus.DebugLevel,
}
// WARNING (END): sourced from newAnsiWriter
return stdIn, stdOut, stdErr
}
// ConsoleStreams returns a wrapped version for each standard stream referencing a console, // ConsoleStreams returns a wrapped version for each standard stream referencing a console,
// that handles ANSI character sequences. // that handles ANSI character sequences.
func ConsoleStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) { func ConsoleStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {