From 2f58bc83cb1aaa88d642d561af062b7a04d15129 Mon Sep 17 00:00:00 2001 From: Felix Kollmann Date: Tue, 3 Apr 2018 04:55:52 +0200 Subject: [PATCH] Unified terminal initialization code handling --- terminal_bsd.go | 8 ++++++-- terminal_linux.go | 8 ++++++-- terminal_windows.go | 9 ++++----- text_formatter.go | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/terminal_bsd.go b/terminal_bsd.go index 3b20604..c498bcd 100644 --- a/terminal_bsd.go +++ b/terminal_bsd.go @@ -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) { } diff --git a/terminal_linux.go b/terminal_linux.go index 78c4298..6eb013e 100644 --- a/terminal_linux.go +++ b/terminal_linux.go @@ -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) { } diff --git a/terminal_windows.go b/terminal_windows.go index c9045a0..2494950 100644 --- a/terminal_windows.go +++ b/terminal_windows.go @@ -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) } } diff --git a/text_formatter.go b/text_formatter.go index c62c412..b4e1f0a 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -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) } } }