From 419a5f3047dd5adc0ac8b45d579f90b74b55ea40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl-Einar=20Bergstr=C3=B8m?= Date: Wed, 14 Oct 2026 16:13:23 +0200 Subject: [PATCH] feat: lazysecrets list's marks take space only when present --- cmd/lazysecrets/list.go | 11 +++++------ cmd/lazysecrets/list_test.go | 12 ++++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/cmd/lazysecrets/list.go b/cmd/lazysecrets/list.go index f684129..951a75e 100644 --- a/cmd/lazysecrets/list.go +++ b/cmd/lazysecrets/list.go @@ -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,10 +184,9 @@ 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)) } - parts = append(parts, render(st, s)) } if m.stars { mark(e.Starred, m.theme.Favourite, "★") diff --git a/cmd/lazysecrets/list_test.go b/cmd/lazysecrets/list_test.go index 95264fd..1780881 100644 --- a/cmd/lazysecrets/list_test.go +++ b/cmd/lazysecrets/list_test.go @@ -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}, ""}, @@ -54,11 +54,11 @@ func TestListRecentAndExpiryMarks(t *testing.T) { e listing.Entry want string }{ - {listing.Entry{Provider: "azure", Starred: true, Recent: true}, "★ ◷ " + az}, - {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", Starred: true, Recent: true}, "★ ◷ " + az}, + {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}, } { if got := m.of(c.e); got != c.want { t.Errorf("%+v: %q, want %q", c.e, got, c.want)