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 86a7632d63
commit 486a1a03d8
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,
}
})
}