2018-11-18 00:28:29 +00:00
|
|
|
// +build !appengine,!js,windows
|
|
|
|
|
|
|
|
package logrus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
2019-06-16 21:33:25 +00:00
|
|
|
|
2020-10-19 21:40:00 +00:00
|
|
|
"golang.org/x/sys/windows"
|
2018-11-18 00:28:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func checkIfTerminal(w io.Writer) bool {
|
|
|
|
switch v := w.(type) {
|
|
|
|
case *os.File:
|
2020-10-19 21:40:00 +00:00
|
|
|
handle := windows.Handle(v.Fd())
|
2018-11-18 00:28:29 +00:00
|
|
|
var mode uint32
|
2020-10-19 21:40:00 +00:00
|
|
|
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-11-18 00:28:29 +00:00
|
|
|
}
|
2020-10-19 21:40:00 +00:00
|
|
|
return false
|
2018-11-18 00:28:29 +00:00
|
|
|
}
|