Windows: run -it not crash in ISE

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2016-05-24 13:03:13 -07:00
parent a531a67461
commit f790161afd
3 changed files with 30 additions and 16 deletions

View file

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

View file

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

View file

@ -3,3 +3,31 @@
// and return pseudo-streams that convert ANSI sequences to / from Windows Console API calls. // and return pseudo-streams that convert ANSI sequences to / from Windows Console API calls.
package windows 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,
}
})
}