浏览代码

Merge pull request #11648 from ahmetalpbalkan/win-cli/ansi-emulation-check

Disable ANSI emulation in certain windows shells
Jessie Frazelle 10 年之前
父节点
当前提交
b094677559
共有 1 个文件被更改,包括 20 次插入1 次删除
  1. 20 1
      pkg/term/term_windows.go

+ 20 - 1
pkg/term/term_windows.go

@@ -3,6 +3,7 @@ package term
 
 
 import (
 import (
 	"io"
 	"io"
+	"os"
 
 
 	"github.com/docker/docker/pkg/term/winconsole"
 	"github.com/docker/docker/pkg/term/winconsole"
 )
 )
@@ -114,5 +115,23 @@ func GetFdInfo(in interface{}) (uintptr, bool) {
 }
 }
 
 
 func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
 func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) {
-	return winconsole.StdStreams()
+	var shouldEmulateANSI bool
+	switch {
+	case os.Getenv("ConEmuANSI") == "ON":
+		// ConEmu shell, ansi emulated by default and ConEmu does an extensively
+		// good emulation.
+		shouldEmulateANSI = false
+	case os.Getenv("MSYSTEM") != "":
+		// MSYS (mingw) cannot fully emulate well and still shows escape characters
+		// mostly because it's still running on cmd.exe window.
+		shouldEmulateANSI = true
+	default:
+		shouldEmulateANSI = true
+	}
+
+	if shouldEmulateANSI {
+		return winconsole.StdStreams()
+	}
+
+	return os.Stdin, os.Stdout, os.Stderr
 }
 }