Merge pull request #22951 from Microsoft/jjh/ise2

Windows: run -it not crash in PowerShell ISE
This commit is contained in:
Alexander Morozov 2016-05-25 16:50:06 -07:00
commit cce0e16ce4
3 changed files with 30 additions and 16 deletions

View file

@ -28,6 +28,7 @@ type ansiReader struct {
}
func newAnsiReader(nFile int) *ansiReader {
initLogger()
file, fd := winterm.GetStdFile(nFile)
return &ansiReader{
file: file,

View file

@ -3,16 +3,12 @@
package windows
import (
"io/ioutil"
"os"
ansiterm "github.com/Azure/go-ansiterm"
"github.com/Azure/go-ansiterm/winterm"
"github.com/Sirupsen/logrus"
)
var logger *logrus.Logger
// ansiWriter wraps a standard output file (e.g., os.Stdout) providing ANSI sequence translation.
type ansiWriter struct {
file *os.File
@ -25,18 +21,7 @@ type ansiWriter struct {
}
func newAnsiWriter(nFile int) *ansiWriter {
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,
}
initLogger()
file, fd := winterm.GetStdFile(nFile)
info, err := winterm.GetConsoleScreenBufferInfo(fd)
if err != nil {

View file

@ -3,3 +3,31 @@
// and return pseudo-streams that convert ANSI sequences to / from Windows Console API calls.
package windows
import (
"io/ioutil"
"os"
"sync"
ansiterm "github.com/Azure/go-ansiterm"
"github.com/Sirupsen/logrus"
)
var logger *logrus.Logger
var initOnce sync.Once
func initLogger() {
initOnce.Do(func() {
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,
}
})
}