Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23
require (
github.com/stretchr/testify v1.10.0
golang.org/x/sys v0.13.0
golang.org/x/term v0.2.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
25 changes: 25 additions & 0 deletions terminal_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build !appengine

package logrus

import (
"io"
"os"

"golang.org/x/term"
)

func checkIfTerminal(w io.Writer) bool {
if f, ok := w.(*os.File); ok {
fd := f.Fd()
maxInt := uintptr(^uint(0) >> 1)
if fd > maxInt || !term.IsTerminal(int(fd)) {
return false
}

// On Windows consoles, ANSI escape sequences are not processed
// unless ENABLE_VIRTUAL_TERMINAL_PROCESSING is set.
return enableVirtualTerminalProcessing(fd)
}
return false
}
12 changes: 0 additions & 12 deletions terminal_check_bsd.go

This file was deleted.

7 changes: 0 additions & 7 deletions terminal_check_no_terminal.go

This file was deleted.

21 changes: 0 additions & 21 deletions terminal_check_notappengine.go

This file was deleted.

13 changes: 0 additions & 13 deletions terminal_check_solaris.go

This file was deleted.

12 changes: 0 additions & 12 deletions terminal_check_unix.go

This file was deleted.

27 changes: 0 additions & 27 deletions terminal_check_windows.go

This file was deleted.

7 changes: 7 additions & 0 deletions terminal_vt_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !windows

package logrus

func enableVirtualTerminalProcessing(fd uintptr) bool {
return true
}
21 changes: 21 additions & 0 deletions terminal_vt_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build windows

package logrus

import "golang.org/x/sys/windows"

func enableVirtualTerminalProcessing(fd uintptr) bool {
h := windows.Handle(fd)

var mode uint32
if err := windows.GetConsoleMode(h, &mode); err != nil {
return false
}
if mode&windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 {
return true
}
if err := windows.SetConsoleMode(h, mode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err != nil {
return false
}
return true
}
Loading