logrus/terminal_check_windows.go

28 lines
490 B
Go
Raw Permalink Normal View History

2018-09-16 11:14:59 +03:00
// +build !appengine,!js,windows
2018-04-03 05:40:58 +03:00
package logrus
import (
"io"
"os"
2019-05-18 12:44:18 +03:00
"golang.org/x/sys/windows"
2018-04-03 05:40:58 +03:00
)
func checkIfTerminal(w io.Writer) bool {
switch v := w.(type) {
case *os.File:
handle := windows.Handle(v.Fd())
2018-04-03 05:40:58 +03:00
var mode uint32
if err := windows.GetConsoleMode(handle, &mode); err != nil {
return false
}
mode |= windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING
if err := windows.SetConsoleMode(handle, mode); err != nil {
return false
}
return true
2018-04-03 05:40:58 +03:00
}
return false
2018-04-03 05:40:58 +03:00
}