1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-26 05:37:18 +02:00
lazygit/vendor/github.com/sirupsen/logrus/terminal_check_windows.go

35 lines
572 B
Go
Raw Normal View History

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