File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -69,35 +69,37 @@ func (s *IOStreams) HasTrueColor() bool {
6969 return s .hasTrueColor
7070}
7171
72- func (s * IOStreams ) DetectTerminalTheme () string {
72+ // DetectTerminalTheme is a utility to call before starting the output pager so that the terminal background
73+ // can be reliably detected.
74+ func (s * IOStreams ) DetectTerminalTheme () {
7375 if ! s .ColorEnabled () {
7476 s .terminalTheme = "none"
75- return "none"
77+ return
7678 }
7779
7880 if s .pagerProcess != nil {
7981 s .terminalTheme = "none"
80- return "none"
82+ return
8183 }
8284
8385 style := os .Getenv ("GLAMOUR_STYLE" )
8486 if style != "" && style != "auto" {
8587 s .terminalTheme = "none"
86- return "none"
88+ return
8789 }
8890
8991 if termenv .HasDarkBackground () {
9092 s .terminalTheme = "dark"
91- return "dark"
93+ return
9294 }
9395
9496 s .terminalTheme = "light"
95- return "light"
9697}
9798
99+ // TerminalTheme returns "light", "dark", or "none" depending on the background color of the terminal.
98100func (s * IOStreams ) TerminalTheme () string {
99101 if s .terminalTheme == "" {
100- return "none"
102+ s . DetectTerminalTheme ()
101103 }
102104
103105 return s .terminalTheme
You can’t perform that action at this time.
0 commit comments