2019-04-21 17:58:15 +00:00
|
|
|
// +build !appengine,!js,windows
|
|
|
|
|
|
|
|
package logrus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"syscall"
|
2019-11-03 17:51:13 +00:00
|
|
|
|
|
|
|
sequences "github.com/konsorten/go-windows-terminal-sequences"
|
2019-04-21 17:58:15 +00:00
|
|
|
)
|
|
|
|
|
2019-11-03 17:51:13 +00:00
|
|
|
func initTerminal(w io.Writer) {
|
|
|
|
switch v := w.(type) {
|
|
|
|
case *os.File:
|
|
|
|
sequences.EnableVirtualTerminalProcessing(syscall.Handle(v.Fd()), true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-21 17:58:15 +00:00
|
|
|
func checkIfTerminal(w io.Writer) bool {
|
2019-11-03 17:51:13 +00:00
|
|
|
var ret bool
|
2019-04-21 17:58:15 +00:00
|
|
|
switch v := w.(type) {
|
|
|
|
case *os.File:
|
|
|
|
var mode uint32
|
|
|
|
err := syscall.GetConsoleMode(syscall.Handle(v.Fd()), &mode)
|
2019-11-03 17:51:13 +00:00
|
|
|
ret = (err == nil)
|
2019-04-21 17:58:15 +00:00
|
|
|
default:
|
2019-11-03 17:51:13 +00:00
|
|
|
ret = false
|
|
|
|
}
|
|
|
|
if ret {
|
|
|
|
initTerminal(w)
|
2019-04-21 17:58:15 +00:00
|
|
|
}
|
2019-11-03 17:51:13 +00:00
|
|
|
return ret
|
2019-04-21 17:58:15 +00:00
|
|
|
}
|