xonecas.io
62159
Sy

symb / commit 70fb78f

fix: modal colors

xonecas2026-02-15 70fb78f19d9adaa5941bb5ea7f97b925b421da7e parent b8e15b3

3 files changed

internal/tui/modal/modal.go+17−11
@@ -26,14 +26,17 @@ type Item struct {
2626 // SearchFunc is called with the current query to produce results.
2727 type SearchFunc func(query string) []Item
2828
29+// Colors holds the theme colors for the modal.
30+type Colors struct {
31+ Dim string
32+ SelFg string
33+ SelBg string
34+ Border string
35+}
36+
2937 const (
3038 debounceDelay = 250 * time.Millisecond
3139
32- colorDim = "#666666"
33- colorSelFg = "#ffffff"
34- colorSelBg = "#444444"
35- colorBorder = "#555555"
36-
3740 keyDown = "down"
3841 keyBackspace = "backspace"
3942 )
@@ -52,15 +55,18 @@ type Model struct {
5255 searchFn SearchFunc
5356 seq int // debounce sequence counter
5457
58+ colors Colors
59+
5560 // Prompt shown before the input text.
5661 Prompt string
5762 }
5863
5964 // New creates a modal with the given search function.
60-func New(searchFn SearchFunc, prompt string) Model {
65+func New(searchFn SearchFunc, prompt string, colors Colors) Model {
6166 m := Model{
6267 searchFn: searchFn,
6368 Prompt: prompt,
69+ colors: colors,
6470 }
6571 // Initial search with empty query.
6672 m.items = searchFn("")
@@ -229,7 +235,7 @@ func (m *Model) View(appWidth, appHeight int) string {
229235 listHeight = 1
230236 }
231237
232- dimStyle := lipgloss.NewStyle().Foreground(lipgloss.Color(colorDim))
238+ dimStyle := lipgloss.NewStyle().Foreground(lipgloss.Color(m.colors.Dim))
233239 divider := dimStyle.Render(strings.Repeat("\u2500", innerW))
234240 listLines := m.renderList(innerW, listHeight)
235241
@@ -240,7 +246,7 @@ func (m *Model) View(appWidth, appHeight int) string {
240246
241247 box := lipgloss.NewStyle().
242248 Border(lipgloss.RoundedBorder()).
243- BorderForeground(lipgloss.Color(colorBorder)).
249+ BorderForeground(lipgloss.Color(m.colors.Border)).
244250 Padding(0, 1).
245251 Width(w - 2).
246252 Render(content)
@@ -269,10 +275,10 @@ func (m *Model) renderList(innerW, listHeight int) []string {
269275 scrollOff = m.selected - listHeight + 1
270276 }
271277
272- dimStyle := lipgloss.NewStyle().Foreground(lipgloss.Color(colorDim))
278+ dimStyle := lipgloss.NewStyle().Foreground(lipgloss.Color(m.colors.Dim))
273279 selStyle := lipgloss.NewStyle().
274- Foreground(lipgloss.Color(colorSelFg)).
275- Background(lipgloss.Color(colorSelBg))
280+ Foreground(lipgloss.Color(m.colors.SelFg)).
281+ Background(lipgloss.Color(m.colors.SelBg))
276282
277283 var lines []string
278284 for i := scrollOff; i < len(m.items) && len(lines) < listHeight; i++ {
internal/tui/modal/modal_test.go+12−10
@@ -6,6 +6,8 @@ import (
66 tea "charm.land/bubbletea/v2"
77 )
88
9+var testColors = Colors{Dim: "#666", SelFg: "#fff", SelBg: "#444", Border: "#555"}
10+
911 func fruits(query string) []Item {
1012 all := []Item{
1113 {Name: "apple"},
@@ -52,7 +54,7 @@ func special(name string) tea.KeyPressMsg {
5254 }
5355
5456 func TestEscapeCloses(t *testing.T) {
55- m := New(fruits, "> ")
57+ m := New(fruits, "> ", testColors)
5658 a, _ := m.HandleMsg(special("esc"))
5759 if _, ok := a.(ActionClose); !ok {
5860 t.Fatalf("expected ActionClose, got %T", a)
@@ -60,7 +62,7 @@ func TestEscapeCloses(t *testing.T) {
6062 }
6163
6264 func TestEnterSelectsFirst(t *testing.T) {
63- m := New(fruits, "> ")
65+ m := New(fruits, "> ", testColors)
6466 a, _ := m.HandleMsg(special("enter"))
6567 sel, ok := a.(ActionSelect)
6668 if !ok {
@@ -72,7 +74,7 @@ func TestEnterSelectsFirst(t *testing.T) {
7274 }
7375
7476 func TestDownThenEnterSelectsHighlighted(t *testing.T) {
75- m := New(fruits, "> ")
77+ m := New(fruits, "> ", testColors)
7678 m.HandleMsg(special("down")) // enter list, selected=0
7779 m.HandleMsg(special("down")) // selected=1
7880 a, _ := m.HandleMsg(special("enter"))
@@ -86,7 +88,7 @@ func TestDownThenEnterSelectsHighlighted(t *testing.T) {
8688 }
8789
8890 func TestUpFromTopReturnsFocusToInput(t *testing.T) {
89- m := New(fruits, "> ")
91+ m := New(fruits, "> ", testColors)
9092 m.HandleMsg(special("down")) // enter list
9193 if !m.inList {
9294 t.Fatal("expected inList=true")
@@ -98,7 +100,7 @@ func TestUpFromTopReturnsFocusToInput(t *testing.T) {
98100 }
99101
100102 func TestTypingProducesDebounceCmd(t *testing.T) {
101- m := New(fruits, "> ")
103+ m := New(fruits, "> ", testColors)
102104 _, cmd := m.HandleMsg(key('a'))
103105 if cmd == nil {
104106 t.Fatal("expected debounce cmd")
@@ -116,7 +118,7 @@ func TestDebounceFiresSearch(t *testing.T) {
116118 }
117119 return nil
118120 }
119- m := New(searchFn, "> ")
121+ m := New(searchFn, "> ", testColors)
120122 // Type 'x'.
121123 m.HandleMsg(key('x'))
122124 seq := m.seq
@@ -135,7 +137,7 @@ func TestStaleDebounceIgnored(t *testing.T) {
135137 }
136138 return nil
137139 }
138- m := New(searchFn, "> ")
140+ m := New(searchFn, "> ", testColors)
139141 m.HandleMsg(key('a'))
140142 staleSeq := m.seq
141143 m.HandleMsg(key('b')) // bumps seq
@@ -147,7 +149,7 @@ func TestStaleDebounceIgnored(t *testing.T) {
147149 }
148150
149151 func TestBackspaceRemovesChar(t *testing.T) {
150- m := New(fruits, "> ")
152+ m := New(fruits, "> ", testColors)
151153 m.HandleMsg(key('a'))
152154 m.HandleMsg(key('b'))
153155 m.HandleMsg(special("backspace"))
@@ -157,7 +159,7 @@ func TestBackspaceRemovesChar(t *testing.T) {
157159 }
158160
159161 func TestViewRenders(t *testing.T) {
160- m := New(fruits, "> ")
162+ m := New(fruits, "> ", testColors)
161163 v := m.View(100, 40)
162164 if v == "" {
163165 t.Fatal("expected non-empty view")
@@ -165,7 +167,7 @@ func TestViewRenders(t *testing.T) {
165167 }
166168
167169 func TestEmptyResultsEnterNoAction(t *testing.T) {
168- m := New(func(string) []Item { return nil }, "> ")
170+ m := New(func(string) []Item { return nil }, "> ", testColors)
169171 a, _ := m.HandleMsg(special("enter"))
170172 if a != nil {
171173 t.Fatalf("expected nil action, got %T", a)
internal/tui/update.go+6−1
@@ -741,7 +741,12 @@ func (m *Model) openFileModal() {
741741 }
742742 return items
743743 }
744- md := modal.New(searchFn, "Open: ")
744+ md := modal.New(searchFn, "Open: ", modal.Colors{
745+ Dim: palette.Dim,
746+ SelFg: palette.Fg,
747+ SelBg: palette.Bg,
748+ Border: palette.Border,
749+ })
745750 m.fileModal = &md
746751 }