feat: the selected row is a shade of the terminal's background
CI / Checks (pull_request) Successful in 24s
PR title / Conventional title (pull_request) Successful in 1s

lazysecrets asks the terminal for its background and shades the
selection from it, a little lighter on a dark background and darker on
a light one, where palette 8 was often too bright to read coloured rows
on. Palette 8 stays until the terminal answers, or if it doesn't, and
a theme's selection colours still win.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kebandClaude Opus 5.5 committed 2026-10-11 23:24:56 +02:00
1 parent b95eeb725b
commit 9963615e51
4 files changed
+64 -2

No files matched your search

+28 -1
View File
@@ -3,6 +3,8 @@
package styles
import (
"image/color"
"charm.land/lipgloss/v2"
"git.kebcloud.no/keb/lazysecrets/internal/provider"
@@ -32,6 +34,10 @@ type Styles struct {
KindAzure lipgloss.Style
KindDatabricks lipgloss.Style
KindRepo lipgloss.Style
// themed marks the selection colours as set by the theme, so
// OnBackground leaves them.
themed, themedBlurred bool
}
func Default() Styles {
@@ -45,7 +51,8 @@ func Default() Styles {
// A background rather than reverse, so the row keeps its colours;
// in every pane, so each shows what's selected in it. The focused
// pane's is bold too.
// pane's is bold too. Palette 8 until the terminal says what its
// background is (OnBackground).
Selected: lipgloss.NewStyle().Background(lipgloss.BrightBlack).Bold(true),
SelectedBlurred: lipgloss.NewStyle().Background(lipgloss.BrightBlack),
Muted: lipgloss.NewStyle().Faint(true),
@@ -76,3 +83,23 @@ func (s Styles) Kind(k provider.Kind) lipgloss.Style {
}
return s.KindAzure
}
// OnBackground shades the selection colours from the terminal's
// background, a little lighter on a dark one and darker on a light one:
// a quiet band that keeps the row's colours readable, where palette 8 is
// often too bright. Colours the theme sets are kept.
func (s Styles) OnBackground(bg color.Color, dark bool) Styles {
shade := func(p float64) color.Color {
if dark {
return lipgloss.Lighten(bg, p)
}
return lipgloss.Darken(bg, p)
}
if !s.themed {
s.Selected = s.Selected.Background(shade(0.09))
}
if !s.themedBlurred {
s.SelectedBlurred = s.SelectedBlurred.Background(shade(0.05))
}
return s
}