DetectTerminalTheme is a utility to call before starting the output pager so that the terminal background can be reliably detected.
()
| 114 | // DetectTerminalTheme is a utility to call before starting the output pager so that the terminal background |
| 115 | // can be reliably detected. |
| 116 | func (s *IOStreams) DetectTerminalTheme() { |
| 117 | if !s.ColorEnabled() || s.pagerProcess != nil { |
| 118 | s.terminalTheme = "none" |
| 119 | return |
| 120 | } |
| 121 | |
| 122 | style := os.Getenv("GLAMOUR_STYLE") |
| 123 | if style != "" && style != "auto" { |
| 124 | // ensure GLAMOUR_STYLE takes precedence over "light" and "dark" themes |
| 125 | s.terminalTheme = "none" |
| 126 | return |
| 127 | } |
| 128 | |
| 129 | s.terminalTheme = s.term.Theme() |
| 130 | } |
| 131 | |
| 132 | // TerminalTheme returns "light", "dark", or "none" depending on the background color of the terminal. |
| 133 | func (s *IOStreams) TerminalTheme() string { |
no test coverage detected