From bb487e068c121ad7129d3d4b6628507038d85d7a Mon Sep 17 00:00:00 2001 From: Felix Kollmann Date: Tue, 3 Apr 2018 00:25:30 +0200 Subject: [PATCH] Added support for text coloring on Windows 10 --- text_formatter.go | 2 ++ text_formatter_linux.go | 6 ++++++ text_formatter_windows.go | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 text_formatter_linux.go create mode 100644 text_formatter_windows.go diff --git a/text_formatter.go b/text_formatter.go index ae91edd..afd9ffb 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -67,6 +67,8 @@ type TextFormatter struct { func (f *TextFormatter) init(entry *Entry) { if entry.Logger != nil { f.isTerminal = checkIfTerminal(entry.Logger.Out) + + f.initTerminal(entry) } } diff --git a/text_formatter_linux.go b/text_formatter_linux.go new file mode 100644 index 0000000..e5fa6a9 --- /dev/null +++ b/text_formatter_linux.go @@ -0,0 +1,6 @@ +// +build !appengine,!gopherjs + +package logrus + +func (f *TextFormatter) initTerminal(entry *Entry) { +} diff --git a/text_formatter_windows.go b/text_formatter_windows.go new file mode 100644 index 0000000..552c5f3 --- /dev/null +++ b/text_formatter_windows.go @@ -0,0 +1,19 @@ +// +build !appengine,!gopherjs + +package logrus + +import ( + "os" + "syscall" + + sequences "github.com/konsorten/go-windows-terminal-sequences" +) + +func (f *TextFormatter) initTerminal(entry *Entry) { + switch v := entry.Logger.Out.(type) { + case *os.File: + handle := syscall.Handle(v.Fd()) + + sequences.EnableVirtualTerminalProcessing(handle, true) + } +}