Skip to content

Commit ca391b3

Browse files
committed
set a fzf color scheme from fang's colors to make it fit in
1 parent d40ac41 commit ca391b3

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

cmd/picker.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ func parsePickerOutput(s string, numRows int) (key string, rowIdx int, err error
106106
return keyLine, rowIdx, nil
107107
}
108108

109+
// build an fzf --color spec that matches the CLI's fang color scheme:
110+
// the table column header color is reused for accents (prompt, pointer,
111+
// matches, etc.) and the comment color for info text. base scheme
112+
// follows the detected terminal background.
113+
func pickerColorSpec() string {
114+
cs := fangColorScheme()
115+
base := "dark"
116+
if !isDarkBackground() {
117+
base = "light"
118+
}
119+
accent := hexColor(cs.Title)
120+
dim := hexColor(cs.Comment)
121+
return fmt.Sprintf(
122+
"%s,header:%s,prompt:%s,pointer:%s,marker:%s,spinner:%s,hl:%s,hl+:%s,info:%s",
123+
base, accent, accent, accent, accent, accent, accent, accent, dim,
124+
)
125+
}
126+
109127
func renderPickerHeader(bindings []pickBinding) string {
110128
parts := make([]string, len(bindings))
111129
for i, b := range bindings {
@@ -135,6 +153,7 @@ func runPicker(headers []string, rows [][]string, bindings []pickBinding) error
135153
"--with-nth", "2..",
136154
"--header", renderPickerHeader(bindings),
137155
"--header-first",
156+
"--color", pickerColorSpec(),
138157
}
139158

140159
expect := make([]string, 0, len(bindings)-1)

cmd/styles.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"image/color"
56
"io"
67
"os"
78
"strings"
@@ -14,14 +15,25 @@ import (
1415
"github.com/charmbracelet/x/term"
1516
)
1617

17-
var fangColorScheme = sync.OnceValue(func() fang.ColorScheme {
18-
isDark := true
19-
if term.IsTerminal(os.Stdout.Fd()) {
20-
isDark = lipgloss.HasDarkBackground(os.Stdin, os.Stdout)
18+
var isDarkBackground = sync.OnceValue(func() bool {
19+
if !term.IsTerminal(os.Stdout.Fd()) {
20+
return true
2121
}
22-
return fang.DefaultColorScheme(lipgloss.LightDark(isDark))
22+
return lipgloss.HasDarkBackground(os.Stdin, os.Stdout)
23+
})
24+
25+
var fangColorScheme = sync.OnceValue(func() fang.ColorScheme {
26+
return fang.DefaultColorScheme(lipgloss.LightDark(isDarkBackground()))
2327
})
2428

29+
func hexColor(c color.Color) string {
30+
if c == nil {
31+
return ""
32+
}
33+
r, g, b, _ := c.RGBA()
34+
return fmt.Sprintf("#%02x%02x%02x", uint8(r>>8), uint8(g>>8), uint8(b>>8))
35+
}
36+
2537
type styledTable struct {
2638
out io.Writer
2739
t *table.Table

0 commit comments

Comments
 (0)