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 package logrus
import "golang.org/x/sys/unix" import (
"io"
"golang.org/x/sys/unix"
)
const ioctlReadTermios = unix.TIOCGETA const ioctlReadTermios = unix.TIOCGETA
type Termios unix.Termios type Termios unix.Termios
func (f *TextFormatter) initTerminal(entry *Entry) { func initTerminal(w io.Writer) {
} }

View File

@ -7,11 +7,15 @@
package logrus package logrus
import "golang.org/x/sys/unix" import (
"io"
"golang.org/x/sys/unix"
)
const ioctlReadTermios = unix.TCGETS const ioctlReadTermios = unix.TCGETS
type Termios unix.Termios type Termios unix.Termios
func (f *TextFormatter) initTerminal(entry *Entry) { func initTerminal(w io.Writer) {
} }

View File

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

View File

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