Signed-off-by: John Howard <jhoward@microsoft.com>
| ... | ... |
@@ -40,8 +40,8 @@ var usingNativeConsole bool |
| 40 | 40 |
func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|
| 41 | 41 |
switch {
|
| 42 | 42 |
case os.Getenv("ConEmuANSI") == "ON":
|
| 43 |
- // The ConEmu shell emulates ANSI well by default. |
|
| 44 |
- return os.Stdin, os.Stdout, os.Stderr |
|
| 43 |
+ // The ConEmu terminal emulates ANSI on output streams well. |
|
| 44 |
+ return windows.ConEmuStreams() |
|
| 45 | 45 |
case os.Getenv("MSYSTEM") != "":
|
| 46 | 46 |
// MSYS (mingw) does not emulate ANSI well. |
| 47 | 47 |
return windows.ConsoleStreams() |
| ... | ... |
@@ -8,8 +8,44 @@ import ( |
| 8 | 8 |
"syscall" |
| 9 | 9 |
|
| 10 | 10 |
"github.com/Azure/go-ansiterm/winterm" |
| 11 |
+ |
|
| 12 |
+ ansiterm "github.com/Azure/go-ansiterm" |
|
| 13 |
+ "github.com/Sirupsen/logrus" |
|
| 14 |
+ "io/ioutil" |
|
| 11 | 15 |
) |
| 12 | 16 |
|
| 17 |
+// ConEmuStreams returns prepared versions of console streams, |
|
| 18 |
+// for proper use in ConEmu terminal. |
|
| 19 |
+// The ConEmu terminal emulates ANSI on output streams well by default. |
|
| 20 |
+func ConEmuStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|
|
| 21 |
+ if IsConsole(os.Stdin.Fd()) {
|
|
| 22 |
+ stdIn = newAnsiReader(syscall.STD_INPUT_HANDLE) |
|
| 23 |
+ } else {
|
|
| 24 |
+ stdIn = os.Stdin |
|
| 25 |
+ } |
|
| 26 |
+ |
|
| 27 |
+ stdOut = os.Stdout |
|
| 28 |
+ stdErr = os.Stderr |
|
| 29 |
+ |
|
| 30 |
+ // WARNING (BEGIN): sourced from newAnsiWriter |
|
| 31 |
+ |
|
| 32 |
+ logFile := ioutil.Discard |
|
| 33 |
+ |
|
| 34 |
+ if isDebugEnv := os.Getenv(ansiterm.LogEnv); isDebugEnv == "1" {
|
|
| 35 |
+ logFile, _ = os.Create("ansiReaderWriter.log")
|
|
| 36 |
+ } |
|
| 37 |
+ |
|
| 38 |
+ logger = &logrus.Logger{
|
|
| 39 |
+ Out: logFile, |
|
| 40 |
+ Formatter: new(logrus.TextFormatter), |
|
| 41 |
+ Level: logrus.DebugLevel, |
|
| 42 |
+ } |
|
| 43 |
+ |
|
| 44 |
+ // WARNING (END): sourced from newAnsiWriter |
|
| 45 |
+ |
|
| 46 |
+ return stdIn, stdOut, stdErr |
|
| 47 |
+} |
|
| 48 |
+ |
|
| 13 | 49 |
// ConsoleStreams returns a wrapped version for each standard stream referencing a console, |
| 14 | 50 |
// that handles ANSI character sequences. |
| 15 | 51 |
func ConsoleStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
|