2
0
mirror of https://github.com/42wim/matterbridge synced 2024-11-03 15:40:24 +00:00
matterbridge/vendor/github.com/sirupsen/logrus/terminal_check_windows.go

35 lines
572 B
Go
Raw Normal View History

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