Merge branch 'win10-color-support' of git://github.com/konsorten/logrus into konsorten-win10-color-support

This commit is contained in:
David Bariod
2018-09-16 09:12:22 +02:00
6 changed files with 59 additions and 3 deletions
+8 -1
View File
@@ -3,8 +3,15 @@
package logrus
import "golang.org/x/sys/unix"
import (
"io"
"golang.org/x/sys/unix"
)
const ioctlReadTermios = unix.TIOCGETA
type Termios unix.Termios
func initTerminal(w io.Writer) {
}
+1 -1
View File
@@ -1,4 +1,4 @@
// +build !appengine,!js
// +build !appengine,!js,!windows
package logrus
+20
View File
@@ -0,0 +1,20 @@
// +build !appengine,!gopherjs,windows
package logrus
import (
"io"
"os"
"syscall"
)
func checkIfTerminal(w io.Writer) bool {
switch v := w.(type) {
case *os.File:
var mode uint32
err := syscall.GetConsoleMode(syscall.Handle(v.Fd()), &mode)
return err == nil
default:
return false
}
}
+8 -1
View File
@@ -7,8 +7,15 @@
package logrus
import "golang.org/x/sys/unix"
import (
"io"
"golang.org/x/sys/unix"
)
const ioctlReadTermios = unix.TCGETS
type Termios unix.Termios
func initTerminal(w io.Writer) {
}
+18
View File
@@ -0,0 +1,18 @@
// +build !appengine,!gopherjs,windows
package logrus
import (
"io"
"os"
"syscall"
sequences "github.com/konsorten/go-windows-terminal-sequences"
)
func initTerminal(w io.Writer) {
switch v := w.(type) {
case *os.File:
sequences.EnableVirtualTerminalProcessing(syscall.Handle(v.Fd()), true)
}
}
+4
View File
@@ -79,6 +79,10 @@ type TextFormatter struct {
func (f *TextFormatter) init(entry *Entry) {
if entry.Logger != nil {
f.isTerminal = checkIfTerminal(entry.Logger.Out)
if f.isTerminal {
initTerminal(entry.Logger.Out)
}
}
}