feat: lazysecrets list prints everything lazysecrets can find, for fzf and editor pickers #70

Merged
keb merged 45 commits from feat/list into main 2026-10-14 21:30:44 +02:00
2 changed files with 16 additions and 9 deletions
Showing only changes of commit 94aa74b05d - Show all commits

No files matched your search

+9 -3
View File
@@ -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 // 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, // 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 // ⚠ 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 // marks them, then the provider's icon. The marks are right-aligned in
// space. // room for every kind turned on, so they sit by the icon and names line
// up.
type marks struct { type marks struct {
theme styles.Styles theme styles.Styles
icons icons.Set icons icons.Set
@@ -183,7 +184,9 @@ type marks struct {
func (m marks) of(e listing.Entry) string { func (m marks) of(e listing.Entry) string {
render := renderer(m.color) render := renderer(m.color)
var parts []string var parts []string
room := 0 // marks turned on
mark := func(on bool, st lipgloss.Style, s string) { mark := func(on bool, st lipgloss.Style, s string) {
room++
if on { if on {
parts = append(parts, render(st, s)) parts = append(parts, render(st, s))
} }
@@ -205,6 +208,7 @@ func (m marks) of(e listing.Entry) string {
mark(true, m.theme.Warning, "⚠") mark(true, m.theme.Warning, "⚠")
} }
} }
pad := strings.Repeat(" ", room-len(parts)) // each mark and its space
kind := provider.Kind("") kind := provider.Kind("")
for _, k := range []provider.Kind{provider.KindAzure, provider.KindDatabricks, provider.KindRepo} { for _, k := range []provider.Kind{provider.KindAzure, provider.KindDatabricks, provider.KindRepo} {
if strings.EqualFold(string(k), e.Provider) { 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 != "" { if icon := strings.TrimSpace(m.icons.Prefix(kind)); icon != "" {
parts = append(parts, render(m.theme.Kind(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 { func renderer(color bool) func(lipgloss.Style, string) string {
+7 -6
View File
@@ -34,7 +34,7 @@ func TestListMarks(t *testing.T) {
want string want string
}{ }{
{plain, listing.Entry{Provider: "azure", Starred: true}, "★ " + az}, {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}, {marks{icons: icons.NerdFont}, listing.Entry{Provider: "azure", Starred: true}, az},
{noIcons, listing.Entry{Provider: "azure", Starred: true}, "★"}, {noIcons, listing.Entry{Provider: "azure", Starred: true}, "★"},
{marks{}, 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 e listing.Entry
want string want string
}{ }{
{listing.Entry{Provider: "azure", Starred: true, Recent: true}, "★ ◷ " + az}, // Right-aligned in room for three: by the icon, names lined up.
{listing.Entry{Provider: "azure", Recent: true}, "◷ " + az}, {listing.Entry{Provider: "azure", Starred: true, Recent: true}, " ★ ◷ " + az},
{listing.Entry{Provider: "azure", Expires: now.Add(-time.Hour)}, "✗ " + az}, {listing.Entry{Provider: "azure", Recent: true}, " ◷ " + az},
{listing.Entry{Provider: "azure", Expires: now.Add(10 * 24 * time.Hour)}, "⚠ " + az}, {listing.Entry{Provider: "azure", Expires: now.Add(-time.Hour)}, " ✗ " + az},
{listing.Entry{Provider: "azure", Expires: now.Add(60 * 24 * 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 { if got := m.of(c.e); got != c.want {
t.Errorf("%+v: %q, want %q", c.e, got, c.want) t.Errorf("%+v: %q, want %q", c.e, got, c.want)