Unified terminal initialization code handling

This commit is contained in:
Felix Kollmann 2018-04-03 04:55:52 +02:00
parent 9bc59a5969
commit 2f58bc83cb
4 changed files with 17 additions and 10 deletions

View File

@ -3,11 +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 (f *TextFormatter) initTerminal(entry *Entry) {
func initTerminal(w io.Writer) {
}

View File

@ -7,11 +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 (f *TextFormatter) initTerminal(entry *Entry) {
func initTerminal(w io.Writer) {
}

View File

@ -3,17 +3,16 @@
package logrus
import (
"io"
"os"
"syscall"
sequences "github.com/konsorten/go-windows-terminal-sequences"
)
func (f *TextFormatter) initTerminal(entry *Entry) {
switch v := entry.Logger.Out.(type) {
func initTerminal(w io.Writer) {
switch v := w.(type) {
case *os.File:
handle := syscall.Handle(v.Fd())
sequences.EnableVirtualTerminalProcessing(handle, true)
sequences.EnableVirtualTerminalProcessing(syscall.Handle(v.Fd()), true)
}
}

View File

@ -68,7 +68,7 @@ func (f *TextFormatter) init(entry *Entry) {
f.isTerminal = checkIfTerminal(entry.Logger.Out)
if f.isTerminal {
f.initTerminal(entry)
initTerminal(entry.Logger.Out)
}
}
}