blob: 572889db2162971561061ca240762fca3777289b [file] [log] [blame]
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -07001// +build !appengine,!js,windows
2
3package logrus
4
5import (
6 "io"
7 "os"
8 "syscall"
9
10 sequences "github.com/konsorten/go-windows-terminal-sequences"
11)
12
13func initTerminal(w io.Writer) {
14 switch v := w.(type) {
15 case *os.File:
16 sequences.EnableVirtualTerminalProcessing(syscall.Handle(v.Fd()), true)
17 }
18}
19
20func checkIfTerminal(w io.Writer) bool {
21 var ret bool
22 switch v := w.(type) {
23 case *os.File:
24 var mode uint32
25 err := syscall.GetConsoleMode(syscall.Handle(v.Fd()), &mode)
26 ret = (err == nil)
27 default:
28 ret = false
29 }
30 if ret {
31 initTerminal(w)
32 }
33 return ret
34}