Skip to content

Commit 2c99922

Browse files
guard HasDarkBackground with TTY check to prevent blocking in non-TTY environments
1 parent 4752ce9 commit 2c99922

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ require (
5757
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
5858
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
5959
golang.org/x/sync v0.19.0 // indirect
60-
golang.org/x/sys v0.42.0 // indirect
60+
golang.org/x/sys v0.43.0 // indirect
61+
golang.org/x/term v0.42.0 // indirect
6162
gopkg.in/yaml.v3 v3.0.1 // indirect
6263
modernc.org/libc v1.66.10 // indirect
6364
modernc.org/mathutil v1.7.1 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBc
117117
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
118118
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
119119
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
120+
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
121+
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
122+
golang.org/x/term v0.42.0 h1:UiKe+zDFmJobeJ5ggPwOshJIVt6/Ft0rcfrXZDLWAWY=
123+
golang.org/x/term v0.42.0/go.mod h1:Dq/D+snpsbazcBG5+F9Q1n2rXV8Ma+71xEjTRufARgY=
120124
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
121125
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
122126
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=

styling/styling.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
"charm.land/lipgloss/v2"
11+
"golang.org/x/term"
1112
"golang.org/x/text/cases"
1213
"golang.org/x/text/language"
1314
)
@@ -81,7 +82,10 @@ var (
8182
)
8283

8384
func init() {
84-
isDark := lipgloss.HasDarkBackground(os.Stdin, os.Stdout)
85+
isDark := true
86+
if term.IsTerminal(int(os.Stdin.Fd())) && term.IsTerminal(int(os.Stdout.Fd())) {
87+
isDark = lipgloss.HasDarkBackground(os.Stdin, os.Stdout)
88+
}
8589
ld := lipgloss.LightDark(isDark)
8690
YellowAdaptive = ld(lipgloss.Color(DarkYellow), lipgloss.Color(LightYellow))
8791
YellowAdaptive2 = ld(lipgloss.Color(DarkYellow), lipgloss.Color(PrimaryYellow))

0 commit comments

Comments
 (0)