From f3f26ac46852920aeaa68c323165c6b7a37c3e4f Mon Sep 17 00:00:00 2001 From: Allie Bayless Date: Wed, 28 Oct 2026 09:24:03 -0500 Subject: [PATCH 1/2] feat(picker): group themes by family, add search, swatches and a sample SoftModal now lists themes under their family with a palette swatch beside each variant, marks the confirmed theme, and shows a sample of the highlighted theme's colors. "/" starts a search that matches family, variant, name or light/dark; navigation then steps through the matches only, and enter will not confirm a theme the filter hides. Themes with no family are listed on their own. HideSwatch lets an application list a runtime-resolved placeholder without a swatch, and ThemeSwatch is exported. The plain Modal keeps its flat layout but honours the search. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 29 ++++- picker.go | 261 +++++++++++++++++++++++++++++++++++++----- picker_groups.go | 119 +++++++++++++++++++ picker_groups_test.go | 250 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 631 insertions(+), 28 deletions(-) create mode 100644 picker_groups.go create mode 100644 picker_groups_test.go diff --git a/README.md b/README.md index 5692d15..d904baa 100644 --- a/README.md +++ b/README.md @@ -229,9 +229,36 @@ cancel. Use the soft-panel variant for the newer Tide-family modal style: ```go -overlay := picker.SoftModal(renderer, 42, m.height, "tidedock") +overlay := picker.SoftModal(renderer, 46, m.height, "tidedock") ``` +The soft-panel picker is the full one: themes are grouped under their family +(`Theme.Family`), with a palette swatch beside each variant, the confirmed theme +marked `●`, and a sample of the highlighted theme (selected row, text, link, +quote, status and tag colors) below the list. Pass the modal's whole height; the +list scrolls to keep the cursor in view, and the sample is dropped when there is +no room for it. + +Press `/` to search. Each word must match a theme's family, variant, name, or +`light`/`dark`, so `rose dawn` finds Rosé Pine Dawn and `light` lists every light +theme. While the search has focus, `picker.Filtering()` is true and typed +letters go to the search instead of navigation; `enter` ends the search and +keeps the filter, `esc` clears it (a second `esc` leaves the search). Up and +down step through the matching themes only, and `enter` will not confirm a theme +the filter hides. `picker.Filter()` returns the search text. `Open` clears it. + +A theme whose colors are only known at runtime can opt out of the swatch: + +```go +picker := tideui.NewThemePicker(tideui.ThemePickerOptions{ + Themes: themes, + HideSwatch: func(t tideui.Theme) bool { return t.Name == "match-desktop" }, +}) +``` + +`ThemeSwatch(theme, plain)` draws the same five-cell swatch for use elsewhere. +The plain `Modal` keeps its flat list, and honours the search too. + ## Soft panels Soft panels render the newer Tide-family modal chrome with the app prefix and diff --git a/picker.go b/picker.go index 556fe2f..8440aba 100644 --- a/picker.go +++ b/picker.go @@ -2,6 +2,7 @@ package tideui import ( "strings" + "unicode/utf8" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" @@ -15,6 +16,9 @@ type ThemePickerOptions struct { InitialTheme string // Title labels the modal. Empty uses "THEME". Title string + // HideSwatch reports themes that should be listed without a palette + // swatch, for a placeholder whose colors are only known at runtime. + HideSwatch func(Theme) bool } // ThemePickerAction reports terminal picker actions after an input update. @@ -33,12 +37,19 @@ const ( // // Applications remain responsible for persistence and terminal background // control sequences after inspecting the picker result and active theme. +// +// Typing "/" starts a filter: each word must match a theme's family, variant, +// name, or "light"/"dark". While a filter is applied, navigation steps through +// the matching themes only. type ThemePicker struct { - themes []Theme - title string - cursor int - confirmed int - opened bool + themes []Theme + title string + cursor int + confirmed int + opened bool + filter string + filtering bool + hideSwatch func(Theme) bool } // NewThemePicker creates a picker with an initially confirmed selection. @@ -54,10 +65,11 @@ func NewThemePicker(options ThemePickerOptions) ThemePicker { } selected := themeIndex(themes, options.InitialTheme) return ThemePicker{ - themes: themes, - title: title, - cursor: selected, - confirmed: selected, + themes: themes, + title: title, + cursor: selected, + confirmed: selected, + hideSwatch: options.HideSwatch, } } @@ -69,6 +81,7 @@ func (p *ThemePicker) Open(confirmedName string) { p.cursor = selected p.confirmed = selected p.opened = true + p.filter, p.filtering = "", false } // SetTitle changes the modal title. Empty restores the default "THEME". Use it @@ -81,6 +94,13 @@ func (p *ThemePicker) SetTitle(title string) { p.title = title } +// Filter returns the search text, and Filtering reports whether the picker is +// currently taking keystrokes for it. +func (p ThemePicker) Filter() string { return p.filter } + +// Filtering reports whether keystrokes are being typed into the search. +func (p ThemePicker) Filtering() bool { return p.filtering } + // Opened reports whether the picker should currently be displayed. func (p ThemePicker) Opened() bool { return p.opened } @@ -103,17 +123,24 @@ func (p *ThemePicker) Update(msg tea.KeyMsg) ThemePickerAction { if !p.opened { return ThemePickerNone } + if p.filtering { + p.updateFilter(msg) + return ThemePickerNone + } switch msg.String() { + case "/": + p.filtering = true case "k", "up": - if p.cursor > 0 { - p.cursor-- - } + p.step(-1) case "j", "down": - if p.cursor < len(p.themes)-1 { - p.cursor++ - } + p.step(1) case "enter": + // A filter can hide the highlighted theme; confirming it would pick + // something the person cannot see. + if entryPos(p.entries(), p.cursor) < 0 { + return ThemePickerNone + } p.confirmed = p.cursor p.opened = false return ThemePickerConfirm @@ -125,6 +152,78 @@ func (p *ThemePicker) Update(msg tea.KeyMsg) ThemePickerAction { return ThemePickerNone } +// updateFilter handles a keystroke while the search line has focus. +func (p *ThemePicker) updateFilter(msg tea.KeyMsg) { + switch msg.Type { + case tea.KeyEsc: + if p.filter != "" { + p.filter = "" + p.keepCursorVisible() + } else { + p.filtering = false + } + case tea.KeyEnter: + p.filtering = false + case tea.KeyBackspace: + if _, size := utf8.DecodeLastRuneInString(p.filter); size > 0 { + p.filter = p.filter[:len(p.filter)-size] + p.keepCursorVisible() + } + case tea.KeyUp: + p.step(-1) + case tea.KeyDown: + p.step(1) + case tea.KeyRunes, tea.KeySpace: + if !msg.Alt { + p.filter += string(msg.Runes) + p.keepCursorVisible() + } + } +} + +// entries is the grouped, filtered list the picker shows. +func (p ThemePicker) entries() []pickerEntry { return pickerEntries(p.themes, p.filter) } + +// step moves the cursor delta themes through the ones the filter leaves +// visible, stopping at the ends. +func (p *ThemePicker) step(delta int) { + var visible []int + for _, entry := range p.entries() { + if entry.header == "" { + visible = append(visible, entry.idx) + } + } + if len(visible) == 0 { + return + } + pos := -1 + for i, idx := range visible { + if idx == p.cursor { + pos = i + } + } + next := 0 + if pos != -1 { + next = max(0, min(len(visible)-1, pos+delta)) + } + p.cursor = visible[next] +} + +// keepCursorVisible moves the cursor onto the first visible theme when a filter +// change hides the highlighted one. +func (p *ThemePicker) keepCursorVisible() { + entries := p.entries() + if entryPos(entries, p.cursor) >= 0 { + return + } + for _, entry := range entries { + if entry.header == "" { + p.cursor = entry.idx + return + } + } +} + // Modal renders the picker as an Overlay for assignment to Layout.Modal. // Height limits the number of rendered themes while keeping the cursor visible. func (p ThemePicker) Modal(renderer Renderer, width, height int) Overlay { @@ -139,10 +238,22 @@ func (p ThemePicker) Modal(renderer Renderer, width, height int) Overlay { rowsAvailable := height - renderer.Styles.Overlay.GetVerticalFrameSize() - titleHeight - footerHeight rowsAvailable = max(1, rowsAvailable) - first, last := VisibleRange(len(p.themes), p.cursor, rowsAvailable) + searching := p.filtering || p.filter != "" + if searching { + rowsAvailable = max(1, rowsAvailable-1) + } + visible := p.visibleThemes() + first, last := VisibleRange(len(visible), max(0, indexOf(visible, p.cursor)), rowsAvailable) innerWidth := max(1, width-renderer.Styles.Overlay.GetHorizontalFrameSize()) - rows := make([]string, 0, last-first) - for index := first; index < last; index++ { + rows := make([]string, 0, last-first+1) + if searching { + line := "/ " + p.filter + if p.filtering { + line += "▏" + } + rows = append(rows, renderer.Styles.OverlayBody.Width(innerWidth).Render(alignRow("", line, "", innerWidth))) + } + for _, index := range visible[first:last] { prefix := " " style := renderer.Styles.OverlayBody if index == p.cursor { @@ -173,6 +284,11 @@ func (p ThemePicker) Modal(renderer Renderer, width, height int) Overlay { // SoftModal renders the picker as a soft-panel Overlay for assignment to // Layout.Modal. Prefix labels the app family member in the top border; empty // uses "tide". +// +// Themes are grouped under their family, with a search line above, a palette +// swatch beside each variant and a sample of the highlighted theme below. +// Height is the whole modal; the list scrolls to keep the cursor in view, and +// the sample is left out when there is no room for it. func (p ThemePicker) SoftModal(renderer Renderer, width, height int, prefix string) Overlay { p.ensureReadable() if width <= 0 { @@ -181,28 +297,119 @@ func (p ThemePicker) SoftModal(renderer Renderer, width, height int, prefix stri if prefix == "" { prefix = "tide" } - rowsAvailable := max(1, height-4) - first, last := VisibleRange(len(p.themes), p.cursor, rowsAvailable) innerWidth := max(1, width-4) - rows := make([]string, 0, last-first+1) - for index := first; index < last; index++ { + chrome := newSoftChrome(renderer.Styles) + plain := renderer.Styles.PlainUI + line := func(s string) string { return padStyled(s, innerWidth, chrome.baseBg) } + + // Search line. + searchText, searchMuted := "to search", true + switch { + case p.filtering: + searchText, searchMuted = p.filter+"▏", false + case p.filter != "": + searchText = p.filter + } + search := renderer.RenderSoftRow(SoftRow{Prefix: "/ ", Text: searchText, Muted: searchMuted}, innerWidth) + + // The panel borders and the body's blank rows take four lines. Below the + // search line and the hints sits the list, then, when it fits, a blank line + // and the three-line sample. + room := max(1, height-4) + sampleLines := 0 + if room-2-4 >= 5 { + sampleLines = 4 + } + // The list takes what is left, but never more than the unfiltered list + // needs: a short list does not pad out the modal, and a long one keeps its + // height while a filter narrows it. + listHeight := max(1, min(room-2-sampleLines, len(pickerEntries(p.themes, "")))) + + entries := p.entries() + rows := make([]string, 0, listHeight) + if len(entries) == 0 { + rows = append(rows, renderer.RenderSoftRow(SoftRow{Text: "no matching themes", Muted: true}, innerWidth)) + } + first, last := VisibleRange(len(entries), max(0, entryPos(entries, p.cursor)), listHeight) + for pos := first; pos < last && len(entries) > 0; pos++ { + entry := entries[pos] + if entry.header != "" { + rows = append(rows, renderer.RenderSoftRow(SoftRow{Prefix: " ", Text: entry.header, Muted: true}, innerWidth)) + continue + } + theme := p.themes[entry.idx] + label, indent := theme.Variant, " " + if label == "" || entry.solo || theme.Family == "" { + label, indent = theme.Label(), " " + } + if entry.idx == p.confirmed { + label += " ●" + if plain { + label = strings.TrimSuffix(label, " ●") + " *" + } + } + suffix := "" + if p.hideSwatch == nil || !p.hideSwatch(theme) { + suffix = ThemeSwatch(theme, plain) + } rows = append(rows, renderer.RenderSoftRow(SoftRow{ - Text: p.themes[index].Label(), - Selected: index == p.cursor, + Prefix: indent, + Text: label, + Suffix: suffix, + Selected: entry.idx == p.cursor, }, innerWidth)) } - rows = append(rows, "", renderer.RenderSoftHints(innerWidth, + for len(rows) < listHeight { + rows = append(rows, line("")) + } + + hints := renderer.RenderSoftHints(innerWidth, + SoftHint{Key: "/", Label: "search"}, SoftHint{Key: "enter", Label: "confirm"}, SoftHint{Key: "esc", Label: "revert"}, - )) + ) + if p.filtering { + hints = renderer.RenderSoftHints(innerWidth, + SoftHint{Key: "type", Label: "filter"}, + SoftHint{Key: "enter", Label: "done"}, + SoftHint{Key: "esc", Label: "clear"}, + ) + } + + lines := append([]string{search}, rows...) + if sampleLines > 0 { + lines = append(lines, line("")) + lines = append(lines, renderPickerSample(p.themes[p.cursor], plain, chrome.baseBg, innerWidth)...) + } + lines = append(lines, hints) return renderer.SoftPanelOverlay(SoftPanel{ Prefix: prefix, Title: strings.ToLower(p.title), - Content: renderer.RenderSoftBody(width, strings.Join(rows, "\n")), + Content: renderer.RenderSoftBody(width, strings.Join(lines, "\n")), Width: width, }) } +// visibleThemes lists the indices of the themes the filter leaves visible. +func (p ThemePicker) visibleThemes() []int { + var out []int + for _, entry := range p.entries() { + if entry.header == "" { + out = append(out, entry.idx) + } + } + return out +} + +func indexOf(values []int, want int) int { + for i, v := range values { + if v == want { + return i + } + } + return -1 +} + func (p *ThemePicker) ensureInitialized() { if len(p.themes) != 0 { return diff --git a/picker_groups.go b/picker_groups.go new file mode 100644 index 0000000..54b39c8 --- /dev/null +++ b/picker_groups.go @@ -0,0 +1,119 @@ +package tideui + +import ( + "strings" + + "github.com/charmbracelet/lipgloss" +) + +// pickerEntry is one line of the grouped picker: a family header or a theme. +type pickerEntry struct { + header string // family name, for a header line + idx int // index into the picker's themes, for a theme row (-1 for headers) + solo bool // the only theme of its family: shown without a header +} + +// themeSearchText is what a filter word is matched against: the family and +// variant, the stored name, and whether the theme is light or dark. +func themeSearchText(t Theme) string { + polarity := "dark" + if t.IsLight() { + polarity = "light" + } + return strings.ToLower(t.Family + " " + t.Variant + " " + t.Name + " " + polarity) +} + +// pickerEntries lists the themes matching every word of filter, grouped under a +// header per family. Themes are grouped by consecutive run, so the order the +// caller gave is kept. A theme with no Family is listed on its own, as is a +// family with a single match. +func pickerEntries(themes []Theme, filter string) []pickerEntry { + words := strings.Fields(strings.ToLower(filter)) + var matched []int + for i, theme := range themes { + text := themeSearchText(theme) + ok := true + for _, word := range words { + if !strings.Contains(text, word) { + ok = false + break + } + } + if ok { + matched = append(matched, i) + } + } + var out []pickerEntry + for start := 0; start < len(matched); { + family := themes[matched[start]].Family + end := start + 1 + for family != "" && end < len(matched) && themes[matched[end]].Family == family { + end++ + } + if end-start == 1 { + out = append(out, pickerEntry{idx: matched[start], solo: true}) + } else { + out = append(out, pickerEntry{header: family, idx: -1}) + for _, i := range matched[start:end] { + out = append(out, pickerEntry{idx: i}) + } + } + start = end + } + return out +} + +// entryPos is the position of theme idx in entries, or -1. +func entryPos(entries []pickerEntry, idx int) int { + for i, entry := range entries { + if entry.header == "" && entry.idx == idx { + return i + } + } + return -1 +} + +// ThemeSwatch draws a theme's accent, success, warning, error and tag colors as +// five colored cells, so variants can be told apart before they are previewed. +// With plain set the cells are "#" characters for terminals without color +// backgrounds. +func ThemeSwatch(theme Theme, plain bool) string { + cell := " " + if plain { + cell = "#" + } + var b strings.Builder + for _, c := range []lipgloss.Color{ + theme.BorderFocus, theme.SuccessColor(), theme.WarningColor(), theme.Error, theme.TagColor(), + } { + b.WriteString(lipgloss.NewStyle().Background(c).Foreground(c).Render(cell)) + } + return b.String() +} + +// renderPickerSample shows a theme's colors in use on the modal surface: a +// selected row, body, muted, link and quote text, and the status and tag +// colors. It is drawn from the previewed theme's own roles, so it is right even +// when the application has not yet rebuilt its renderer for the preview. +func renderPickerSample(theme Theme, plain bool, surface lipgloss.Color, width int) []string { + chrome := newSoftChromeOn(Styles{Theme: theme, PlainUI: plain}, surface) + on := func(fg lipgloss.Color, s string) string { + return lipgloss.NewStyle().Background(surface).Foreground(Legible(fg, surface, 4.5)).Render(s) + } + pill := func(c lipgloss.Color, s string) string { + return lipgloss.NewStyle().Background(c).Foreground(contrastFg(c)).Render(" " + s + " ") + } + gap := on(chrome.text, " ") + + selected := padStyled( + lipgloss.NewStyle().Background(chrome.selectedBg).Foreground(chrome.selectedText).Bold(true).Render(" selected row"), + width, chrome.selectedBg) + text := strings.Join([]string{ + on(chrome.text, "text"), on(chrome.muted, "muted"), on(theme.LinkColor(), "link"), on(theme.QuoteColor(), "│ quote"), + }, gap) + status := strings.Join([]string{ + on(theme.SuccessColor(), "ok"), on(theme.WarningColor(), "warn"), on(theme.ErrorColor(), "error"), + pill(theme.TagColor(), "tag"), pill(theme.MatchColor(), "match"), + }, gap) + return []string{selected, padStyled(text, width, surface), padStyled(status, width, surface)} +} diff --git a/picker_groups_test.go b/picker_groups_test.go new file mode 100644 index 0000000..0eea40b --- /dev/null +++ b/picker_groups_test.go @@ -0,0 +1,250 @@ +package tideui + +import ( + "strings" + "testing" + + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/lipgloss" + "github.com/charmbracelet/x/ansi" +) + +func entryNames(entries []pickerEntry, themes []Theme) []string { + var out []string + for _, entry := range entries { + if entry.header == "" { + out = append(out, themes[entry.idx].Name) + } + } + return out +} + +func TestPickerEntriesGroupVariantsUnderTheirFamily(t *testing.T) { + entries := pickerEntries(BuiltinThemes, "") + if entries[0].header != "Catppuccin" { + t.Fatalf("first entry = %+v, want the Catppuccin header", entries[0]) + } + solo := map[string]bool{} + for _, entry := range entries { + if entry.solo { + solo[BuiltinThemes[entry.idx].Name] = true + } + } + for _, want := range []string{"nord", "palenight", "vt52"} { + if !solo[want] { + t.Errorf("%s should be a header-less single-theme row (solo = %v)", want, solo) + } + } + if got := len(entryNames(entries, BuiltinThemes)); got != len(BuiltinThemes) { + t.Fatalf("unfiltered picker lists %d themes, want all %d", got, len(BuiltinThemes)) + } +} + +func TestPickerEntriesLeaveFamilylessThemesUngrouped(t *testing.T) { + themes := []Theme{{Name: "one"}, {Name: "two"}} + for _, entry := range pickerEntries(themes, "") { + if entry.header != "" || !entry.solo { + t.Fatalf("a theme with no family should stand alone, got %+v", entry) + } + } +} + +func TestPickerEntriesFilter(t *testing.T) { + names := func(filter string) []string { return entryNames(pickerEntries(BuiltinThemes, filter), BuiltinThemes) } + + if got := names("latte"); len(got) != 1 || got[0] != "catppuccin-latte" { + t.Errorf(`filter "latte" = %v`, got) + } + if got := names("rose dawn"); len(got) != 1 || got[0] != "rose-pine-dawn" { + t.Errorf(`filter "rose dawn" = %v, want every word to match`, got) + } + if got := names("zzzz"); len(got) != 0 { + t.Errorf(`filter "zzzz" = %v, want none`, got) + } + light := names("light") + if len(light) < 8 { + t.Fatalf(`filter "light" = %v, want the light themes`, light) + } + for _, name := range light { + theme, _ := ThemeByName(name) + if !theme.IsLight() { + t.Errorf(`filter "light" matched dark theme %s`, name) + } + } +} + +func typeInto(p *ThemePicker, text string) { + for _, r := range text { + p.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}}) + } +} + +func TestThemePickerSearchPreviewsFirstMatchAndEscClears(t *testing.T) { + picker := NewThemePicker(ThemePickerOptions{InitialTheme: "catppuccin-mocha"}) + picker.Open("catppuccin-mocha") + + picker.Update(keyMsg("/")) + if !picker.Filtering() { + t.Fatal("/ should start the search") + } + typeInto(&picker, "nord") + // "nord" also matches Nightfox's Nordfox; the cursor lands on the first match. + if got := picker.PreviewTheme().Name; got != "nord" { + t.Fatalf("typing a filter should preview the first match, got %s", got) + } + if picker.Filter() != "nord" { + t.Fatalf("filter = %q", picker.Filter()) + } + + // Letters typed into the search are not navigation keys. + typeInto(&picker, "k") + if picker.Filter() != "nordk" { + t.Fatalf("k should be typed into the search, filter = %q", picker.Filter()) + } + picker.Update(tea.KeyMsg{Type: tea.KeyBackspace}) + if picker.Filter() != "nord" { + t.Fatalf("backspace left filter %q", picker.Filter()) + } + + picker.Update(tea.KeyMsg{Type: tea.KeyEsc}) + if picker.Filter() != "" || !picker.Filtering() { + t.Fatalf("first esc clears the filter and keeps searching: filter %q filtering %v", picker.Filter(), picker.Filtering()) + } + if action := picker.Update(tea.KeyMsg{Type: tea.KeyEsc}); action != ThemePickerNone || !picker.Opened() || picker.Filtering() { + t.Fatalf("second esc leaves the search, not the picker: action %v opened %v filtering %v", action, picker.Opened(), picker.Filtering()) + } +} + +func TestThemePickerNavigationStaysWithinTheFilter(t *testing.T) { + picker := NewThemePicker(ThemePickerOptions{InitialTheme: "catppuccin-mocha"}) + picker.Open("catppuccin-mocha") + picker.Update(keyMsg("/")) + typeInto(&picker, "tokyo") + picker.Update(tea.KeyMsg{Type: tea.KeyEnter}) // done typing, filter stays applied + + var seen []string + for range 8 { + seen = append(seen, picker.PreviewTheme().Name) + picker.Update(keyMsg("j")) + } + for _, name := range seen { + if !strings.HasPrefix(name, "tokyo-night") { + t.Fatalf("navigation left the filtered themes: %v", seen) + } + } + if got := picker.PreviewTheme().Name; got != "tokyo-night-day" { + t.Fatalf("down should stop at the last match, got %s", got) + } +} + +func TestThemePickerEnterIgnoresAThemeTheFilterHides(t *testing.T) { + picker := NewThemePicker(ThemePickerOptions{InitialTheme: "nord"}) + picker.Open("nord") + picker.Update(keyMsg("/")) + typeInto(&picker, "zzzz") // nothing matches, so the highlighted theme is not listed + picker.Update(tea.KeyMsg{Type: tea.KeyEnter}) + if action := picker.Update(tea.KeyMsg{Type: tea.KeyEnter}); action == ThemePickerConfirm { + t.Fatal("enter must not confirm a theme the filter hides") + } +} + +func TestThemePickerOpenClearsTheFilter(t *testing.T) { + picker := NewThemePicker(ThemePickerOptions{}) + picker.Open("nord") + picker.Update(keyMsg("/")) + typeInto(&picker, "dark") + picker.Open("nord") + if picker.Filter() != "" || picker.Filtering() { + t.Fatalf("reopening should clear the search, got %q filtering %v", picker.Filter(), picker.Filtering()) + } +} + +func TestThemePickerSoftModalShowsGroupsSwatchAndSample(t *testing.T) { + renderer := NewRenderer(CatppuccinMocha, StyleOptions{Density: Compact}) + picker := NewThemePicker(ThemePickerOptions{InitialTheme: "catppuccin-mocha"}) + picker.Open("catppuccin-mocha") + + view := ansi.Strip(picker.SoftModal(renderer, 46, 30, "tide").Content) + for _, want := range []string{"/ to search", "Catppuccin", "Mocha ●", "Macchiato", "selected row", "link", "quote", "error", "match", "search", "confirm", "revert"} { + if !strings.Contains(view, want) { + t.Errorf("soft modal is missing %q:\n%s", want, view) + } + } + + picker.Update(keyMsg("/")) + typeInto(&picker, "zzzz") + view = ansi.Strip(picker.SoftModal(renderer, 46, 30, "tide").Content) + if !strings.Contains(view, "no matching themes") { + t.Errorf("an empty result should say so:\n%s", view) + } + if !strings.Contains(view, "zzzz") || !strings.Contains(view, "clear") || !strings.Contains(view, "done") { + t.Errorf("search text and the filtering hints should show:\n%s", view) + } +} + +func TestThemePickerSoftModalFitsItsHeightAndScrollsToTheCursor(t *testing.T) { + renderer := NewRenderer(CatppuccinMocha, StyleOptions{Density: Compact}) + picker := NewThemePicker(ThemePickerOptions{InitialTheme: "catppuccin-mocha"}) + picker.Open("catppuccin-mocha") + for range len(BuiltinThemes) - 1 { + picker.Update(keyMsg("j")) + } + last := BuiltinThemes[len(BuiltinThemes)-1] + + for _, height := range []int{10, 14, 20, 26, 40} { + content := picker.SoftModal(renderer, 46, height, "tide").Content + view := ansi.Strip(content) + lines := strings.Split(content, "\n") + if len(lines) > height { + t.Errorf("height %d: modal is %d lines tall", height, len(lines)) + } + for i, line := range lines { + if got := lipgloss.Width(line); got != 48 { + t.Fatalf("height %d line %d width = %d, want 48", height, i, got) + } + } + if !strings.Contains(view, last.Label()) { + t.Errorf("height %d: the highlighted last theme %q is not visible:\n%s", height, last.Label(), view) + } + } +} + +func TestThemePickerHideSwatchOmitsOnlyThatTheme(t *testing.T) { + renderer := NewRenderer(VT52, StyleOptions{Density: Compact}) // plain UI: swatch cells are "#" + picker := NewThemePicker(ThemePickerOptions{ + Themes: []Theme{Nord, Dracula}, + HideSwatch: func(theme Theme) bool { return theme.Name == Dracula.Name }, + }) + picker.Open(Nord.Name) + view := ansi.Strip(picker.SoftModal(renderer, 40, 12, "tide").Content) + var nordRow, draculaRow string + for _, line := range strings.Split(view, "\n") { + switch { + case strings.Contains(line, "Nord"): + nordRow = line + case strings.Contains(line, "Dracula"): + draculaRow = line + } + } + if !strings.Contains(nordRow, "#####") { + t.Errorf("Nord should carry a swatch: %q", nordRow) + } + if strings.Contains(draculaRow, "#") { + t.Errorf("Dracula's swatch should be hidden: %q", draculaRow) + } +} + +func TestLegacyModalHonoursTheFilter(t *testing.T) { + renderer := NewRenderer(CatppuccinMocha, StyleOptions{Density: Compact}) + picker := NewThemePicker(ThemePickerOptions{Themes: []Theme{CatppuccinMocha, Nord, Dracula}}) + picker.Open(CatppuccinMocha.Name) + if rows := strings.Count(picker.Modal(renderer, 40, 20).Content, "\n") + 1; rows != 3 { + t.Fatalf("an idle picker keeps its plain three-row layout, got %d rows", rows) + } + picker.Update(keyMsg("/")) + typeInto(&picker, "nord") + content := ansi.Strip(picker.Modal(renderer, 40, 20).Content) + if !strings.Contains(content, "/ nord") || !strings.Contains(content, "Nord") || strings.Contains(content, "Dracula") { + t.Fatalf("legacy modal should show the search and only the matches:\n%s", content) + } +} From c0863a0df1eb3c900e320dbd078ef5db7b384c30 Mon Sep 17 00:00:00 2001 From: Allie Bayless Date: Wed, 28 Oct 2026 09:45:34 -0500 Subject: [PATCH 2/2] feat(theme): remove the Shades of Purple theme Brings the collection to 51 themes in 23 families. A saved "shades-of-purple" now resolves to the default theme, like any unknown name. Co-Authored-By: Claude Sonnet 5.5 --- README.md | 2 +- themes_collection.go | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index d904baa..e9214ca 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ theme, ok := tideui.ThemeByName("nord") // false if unknown for _, t := range tideui.BuiltinThemes { /* ... */ } ``` -`BuiltinThemes` holds 52 themes in 24 families (Catppuccin, Tokyo Night, Rosé +`BuiltinThemes` holds 51 themes in 23 families (Catppuccin, Tokyo Night, Rosé Pine, Gruvbox, Solarized, Nightfox, Kanagawa, Ayu, GitHub, Nord, Dracula, One Dark Pro and more), grouped so that variants of a family are adjacent. The palettes are copied from each upstream project's source, with their licenses, diff --git a/themes_collection.go b/themes_collection.go index 24c938e..6646983 100644 --- a/themes_collection.go +++ b/themes_collection.go @@ -179,12 +179,6 @@ var ( Synthwave84 = collectionTheme("synthwave-84", "SynthWave '84", "SynthWave '84", palette{bg: "262335", fg: "ffffff", border: "495495", accent: "ff7edb", surface: "241b2f", muted: "848bbd", red: "fe4450", green: "72f1b8", yellow: "fede5d", link: "36f9f6", quote: "03edf9", tag: "b893ce", match: "f97e72", cursor: "ffffff"}) ) -// Shades of Purple — https://github.com/ahmadawais/shades-of-purple-vscode (MIT). -var ( - // ShadesOfPurple is the Shades of Purple Shades of Purple palette. - ShadesOfPurple = collectionTheme("shades-of-purple", "Shades of Purple", "Shades of Purple", palette{bg: "2d2b55", fg: "ffffff", border: "1e1e3f", accent: "b362ff", surface: "222244", muted: "a599e9", red: "ec3a37", green: "3ad900", yellow: "fad000", link: "b362ff", quote: "80fcff", tag: "ff2c70", match: "ff7300", cursor: "fad000"}) -) - // Oxocarbon — https://github.com/nyoom-engineering/oxocarbon.nvim (MIT). var ( // OxocarbonDark is the Oxocarbon Dark palette. @@ -297,7 +291,6 @@ var BuiltinThemes = []Theme{ NightOwl, NightOwlLight, Synthwave84, - ShadesOfPurple, OxocarbonDark, OxocarbonLight, Cyberdream,