feat: lazysecrets list's marks take space only when present

This commit is contained in:
keb committed 2026-10-14 21:24:01 +02:00
1 parent c548688715
commit 419a5f3047
2 files changed
+7 -8

No files matched your search

+5 -6
View File
@@ -169,9 +169,9 @@ func nameOf(e listing.Entry, theme styles.Styles, color bool) string {
// marks says what goes before the name, in a field of its own so a
// search leaves it out: ★ for a starred entry, ◷ for one used lately,
// ⚠ for one expiring within warn and ✗ for an expired one (as the TUI
// marks them; a space as wide where it isn't, so names line up), then the
// provider's icon.
// ⚠ for one expiring within warn and ✗ for an expired one, as the TUI
// marks them, then the provider's icon. Only the marks an entry has take
// space.
type marks struct {
theme styles.Styles
icons icons.Set
@@ -184,11 +184,10 @@ func (m marks) of(e listing.Entry) string {
render := renderer(m.color)
var parts []string
mark := func(on bool, st lipgloss.Style, s string) {
if !on {
s = " "
}
if on {
parts = append(parts, render(st, s))
}
}
if m.stars {
mark(e.Starred, m.theme.Favourite, "★")
}
+2 -2
View File
@@ -34,7 +34,7 @@ func TestListMarks(t *testing.T) {
want string
}{
{plain, listing.Entry{Provider: "azure", Starred: true}, "★ " + az},
{plain, listing.Entry{Provider: "azure"}, " " + az}, // as wide as ★
{plain, listing.Entry{Provider: "azure"}, az}, // no space for a star it hasn't
{marks{icons: icons.NerdFont}, listing.Entry{Provider: "azure", Starred: true}, az},
{noIcons, listing.Entry{Provider: "azure", Starred: true}, "★"},
{marks{}, listing.Entry{Provider: "azure", Starred: true}, ""},
@@ -58,7 +58,7 @@ func TestListRecentAndExpiryMarks(t *testing.T) {
{listing.Entry{Provider: "azure", Recent: true}, "◷ " + az},
{listing.Entry{Provider: "azure", Expires: now.Add(-time.Hour)}, "✗ " + az},
{listing.Entry{Provider: "azure", Expires: now.Add(10 * 24 * time.Hour)}, "⚠ " + az},
{listing.Entry{Provider: "azure", Expires: now.Add(60 * 24 * time.Hour)}, " " + az},
{listing.Entry{Provider: "azure", Expires: now.Add(60 * 24 * time.Hour)}, az},
} {
if got := m.of(c.e); got != c.want {
t.Errorf("%+v: %q, want %q", c.e, got, c.want)