From 94aa74b05dae787ce4c44711fc0203d7cb6b56e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl-Einar=20Bergstr=C3=B8m?= Date: Wed, 14 Oct 2026 16:15:49 +0200 Subject: [PATCH] feat: lazysecrets list right-aligns the marks by the icon, so names line up --- cmd/lazysecrets/list.go | 12 +++++++++--- cmd/lazysecrets/list_test.go | 13 +++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cmd/lazysecrets/list.go b/cmd/lazysecrets/list.go index 951a75e..0872f40 100644 --- a/cmd/lazysecrets/list.go +++ b/cmd/lazysecrets/list.go @@ -170,8 +170,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, then the provider's icon. Only the marks an entry has take -// space. +// marks them, then the provider's icon. The marks are right-aligned in +// room for every kind turned on, so they sit by the icon and names line +// up. type marks struct { theme styles.Styles icons icons.Set @@ -183,7 +184,9 @@ type marks struct { func (m marks) of(e listing.Entry) string { render := renderer(m.color) var parts []string + room := 0 // marks turned on mark := func(on bool, st lipgloss.Style, s string) { + room++ if on { parts = append(parts, render(st, s)) } @@ -205,6 +208,7 @@ func (m marks) of(e listing.Entry) string { mark(true, m.theme.Warning, "⚠") } } + pad := strings.Repeat(" ", room-len(parts)) // each mark and its space kind := provider.Kind("") for _, k := range []provider.Kind{provider.KindAzure, provider.KindDatabricks, provider.KindRepo} { if strings.EqualFold(string(k), e.Provider) { @@ -213,8 +217,10 @@ func (m marks) of(e listing.Entry) string { } if icon := strings.TrimSpace(m.icons.Prefix(kind)); icon != "" { parts = append(parts, render(m.theme.Kind(kind), icon)) + } else if len(parts) > 0 { + pad = strings.TrimSuffix(pad, " ") // nothing after the last mark } - return strings.Join(parts, " ") + return pad + strings.Join(parts, " ") } func renderer(color bool) func(lipgloss.Style, string) string { diff --git a/cmd/lazysecrets/list_test.go b/cmd/lazysecrets/list_test.go index 1780881..005ef35 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}, // no space for a star it hasn't + {plain, listing.Entry{Provider: "azure"}, " " + az}, // room for the star, so names line up {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,12 @@ 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}, + // Right-aligned in room for three: by the icon, names lined up. + {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)