Skip to content

Commit 87d959b

Browse files
committed
use golang.org/x/term for terminal detection
Using a low version of this dependency, as the `IsTerminal` function was not modified in newer versions; golang/term@v0.2.0...v0.40.0 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 5d77857 commit 87d959b

12 files changed

+22
-118
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ go 1.17
44

55
require (
66
github.com/stretchr/testify v1.10.0
7-
golang.org/x/sys v0.13.0
7+
golang.org/x/term v0.2.0
88
)
99

1010
require (
1111
github.com/davecgh/go-spew v1.1.1 // indirect
1212
github.com/pmezard/go-difflib v1.0.0 // indirect
13+
golang.org/x/sys v0.13.0 // indirect
1314
gopkg.in/yaml.v3 v3.0.1 // indirect
1415
)

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
1212
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
1313
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
1414
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
15+
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1516
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
1617
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
18+
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
19+
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
1720
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1821
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1922
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

terminal_check.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// +build !appengine
2+
3+
package logrus
4+
5+
import (
6+
"io"
7+
"os"
8+
9+
"golang.org/x/term"
10+
)
11+
12+
func checkIfTerminal(w io.Writer) bool {
13+
if f, ok := w.(*os.File); ok {
14+
return term.IsTerminal(int(f.Fd())) // #nosec G115 -- Fd() is OS-provided, not user-controlled; overflow not attacker-influenced
15+
}
16+
return false
17+
}

terminal_check_bsd.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

terminal_check_js.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

terminal_check_no_terminal.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

terminal_check_notappengine.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

terminal_check_solaris.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

terminal_check_unix.go

Lines changed: 0 additions & 15 deletions
This file was deleted.

terminal_check_wasi.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)