File tree Expand file tree Collapse file tree 3 files changed +25
-32
lines changed
Expand file tree Collapse file tree 3 files changed +25
-32
lines changed Original file line number Diff line number Diff line change 1- //go:build !windows && ! appengine
1+ //go:build !appengine
22
33package logrus
44
@@ -16,7 +16,10 @@ func checkIfTerminal(w io.Writer) bool {
1616 if fd > maxInt {
1717 return false
1818 }
19- return term .IsTerminal (int (fd ))
19+ if ! term .IsTerminal (int (fd )) {
20+ return false
21+ }
22+ return enableVirtualTerminalProcessing (fd )
2023 }
2124 return false
2225}
Original file line number Diff line number Diff line change 1+ //go:build unix
2+
3+ package logrus
4+
5+ func enableVirtualTerminalProcessing (fd uintptr ) bool {
6+ return true
7+ }
Original file line number Diff line number Diff line change 22
33package logrus
44
5- import (
6- "io"
7- "os"
5+ import "golang.org/x/sys/windows"
86
9- "golang.org/x/sys/windows"
10- "golang.org/x/term"
11- )
7+ func enableVirtualTerminalProcessing (fd uintptr ) bool {
8+ h := windows .Handle (fd )
129
13- func checkIfTerminal (w io.Writer ) bool {
14- if f , ok := w .(* os.File ); ok {
15- fd := f .Fd ()
16- maxInt := uintptr (^ uint (0 ) >> 1 )
17- if fd > maxInt {
18- return false
19- }
20- if ! term .IsTerminal (int (f .Fd ())) {
21- return false
22- }
23-
24- h := windows .Handle (f .Fd ())
25- var mode uint32
26- if err := windows .GetConsoleMode (h , & mode ); err != nil {
27- return false
28- }
29- if mode & windows .ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 {
30- return true
31- }
32- mode |= windows .ENABLE_VIRTUAL_TERMINAL_PROCESSING
33- if err := windows .SetConsoleMode (h , mode ); err != nil {
34- return false
35- }
10+ var mode uint32
11+ if err := windows .GetConsoleMode (h , & mode ); err != nil {
12+ return false
13+ }
14+ if mode & windows .ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 {
15+ return true
16+ }
17+ if err := windows .SetConsoleMode (h , mode | windows .ENABLE_VIRTUAL_TERMINAL_PROCESSING ); err != nil {
18+ return false
3619 }
37- return false
20+ return true
3821}
You can’t perform that action at this time.
0 commit comments