File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,8 +62,9 @@ type Config struct {
6262 Format string
6363 FileOutput string
6464 Verbose bool
65- NoSyntax bool // disable syntax highlighting
66- Dedup bool // collapse byte-identical matches
65+ NoSyntax bool // disable syntax highlighting
66+ Dedup bool // collapse byte-identical matches
67+ Color string // color mode: auto, always, never
6768
6869 // MCP
6970 MCPServer bool
Original file line number Diff line number Diff line change @@ -58,15 +58,23 @@ func ConsoleSearch(cfg *Config) {
5858}
5959
6060func formatDefault (cfg * Config , results []* common.FileJob ) {
61- noColor := os .Getenv ("TERM" ) == "dumb" ||
62- (! isatty .IsTerminal (os .Stdout .Fd ()) && ! isatty .IsCygwinTerminal (os .Stdout .Fd ()))
61+ var noColor bool
62+ switch cfg .Color {
63+ case "always" :
64+ noColor = false
65+ case "never" :
66+ noColor = true
67+ default : // "auto"
68+ noColor = os .Getenv ("TERM" ) == "dumb" ||
69+ (! isatty .IsTerminal (os .Stdout .Fd ()) && ! isatty .IsCygwinTerminal (os .Stdout .Fd ()))
70+ }
71+ color .NoColor = noColor
6372
6473 fmtBegin := "\033 [1;31m"
6574 fmtEnd := "\033 [0m"
6675 if noColor {
6776 fmtBegin = ""
6877 fmtEnd = ""
69- color .NoColor = true
7078 }
7179
7280 documentFrequency := ranker .CalculateDocumentTermFrequency (results )
Original file line number Diff line number Diff line change @@ -313,6 +313,12 @@ func main() {
313313 false ,
314314 "disable syntax highlighting in output" ,
315315 )
316+ flags .StringVar (
317+ & cfg .Color ,
318+ "color" ,
319+ "auto" ,
320+ "color output mode [auto, always, never]" ,
321+ )
316322 flags .Float64Var (
317323 & cfg .WeightCode ,
318324 "weight-code" ,
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import (
1515 "github.com/charmbracelet/bubbles/textinput"
1616 tea "github.com/charmbracelet/bubbletea"
1717 "github.com/charmbracelet/lipgloss"
18+ "github.com/muesli/termenv"
1819)
1920
2021// searchResult represents a single search result
@@ -127,6 +128,13 @@ type model struct {
127128}
128129
129130func initialModel (cfg * Config ) model {
131+ switch cfg .Color {
132+ case "always" :
133+ lipgloss .SetColorProfile (termenv .ANSI256 )
134+ case "never" :
135+ lipgloss .SetColorProfile (termenv .Ascii )
136+ }
137+
130138 si := textinput .New ()
131139 si .Placeholder = "search query..."
132140 si .Prompt = "> "
You can’t perform that action at this time.
0 commit comments