feat: lazysecrets list puts the note icon before the note, not in the marks

This commit is contained in:
keb committed 2026-10-14 21:24:01 +02:00
1 parent 1c5a6a5087
commit c80a84cada
2 files changed
+30 -26

No files matched your search

+19 -10
View File
@@ -52,7 +52,7 @@ func listCmd(providers []provider.Provider, st *store.Store, cachePath string, t
iconsOn := fs.Bool("icons", withIcons, "put the provider's Nerd Font icon before names (text)") iconsOn := fs.Bool("icons", withIcons, "put the provider's Nerd Font icon before names (text)")
stars := fs.Bool("stars", true, "put ★ before starred names, in the theme's favouriteColor (text)") stars := fs.Bool("stars", true, "put ★ before starred names, in the theme's favouriteColor (text)")
recent := fs.Bool("recent", withRecent, "put ◷ before names used lately, in mutedColor (text; default ui.recentIcon)") recent := fs.Bool("recent", withRecent, "put ◷ before names used lately, in mutedColor (text; default ui.recentIcon)")
notes := fs.Bool("notes", true, "put a note icon (✎ without --icons) before names with a note, in mutedColor (text; the note is printed either way)") notes := fs.Bool("notes", true, "start a note with a note icon (✎ without --icons) (text; the note is printed either way)")
expiry := fs.Bool("expiry", true, "mark and say which have expired (✗ expired) or expire within ui.expiryWarningDays (⚠ expires in 12d) (text)") expiry := fs.Bool("expiry", true, "mark and say which have expired (✗ expired) or expire within ui.expiryWarningDays (⚠ expires in 12d) (text)")
kinds := fs.String("kind", "", "only these kinds, comma-separated: "+strings.Join(listing.Kinds, ", ")+" (vault: also scopes and repo files)") kinds := fs.String("kind", "", "only these kinds, comma-separated: "+strings.Join(listing.Kinds, ", ")+" (vault: also scopes and repo files)")
showErrors := fs.Bool("errors", true, "list the lists that can't be read, with why (text: ✗ lines; json: \"error\")") showErrors := fs.Bool("errors", true, "list the lists that can't be read, with why (text: ✗ lines; json: \"error\")")
@@ -76,7 +76,7 @@ func listCmd(providers []provider.Provider, st *store.Store, cachePath string, t
return fmt.Errorf("--color: %q is not always or never", *color) return fmt.Errorf("--color: %q is not always or never", *color)
} }
now := time.Now() now := time.Now()
m := marks{theme: theme, icons: icons.None, stars: *stars, recent: *recent, notes: *notes, expiry: *expiry, m := marks{theme: theme, icons: icons.None, stars: *stars, recent: *recent, expiry: *expiry,
color: *color == "always", warn: expiryWarn, now: now} color: *color == "always", warn: expiryWarn, now: now}
if *iconsOn { if *iconsOn {
m.icons = icons.NerdFont m.icons = icons.NerdFont
@@ -94,7 +94,7 @@ func listCmd(providers []provider.Provider, st *store.Store, cachePath string, t
if status == "" && *expiry { if status == "" && *expiry {
status = expiryOf(e, theme, expiryWarn, now, colored) status = expiryOf(e, theme, expiryWarn, now, colored)
} }
note := renderer(colored)(theme.Muted, e.Note) note := noteOf(e, theme, m.icons, *notes, colored)
// A tab or line break in a name would break the line up. // A tab or line break in a name would break the line up.
_, err := fmt.Fprintf(out, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", e.Kind, mark, oneLine.Replace(name), oneLine.Replace(status), _, err := fmt.Fprintf(out, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", e.Kind, mark, oneLine.Replace(name), oneLine.Replace(status),
oneLine.Replace(note), e.Account, e.Link) oneLine.Replace(note), e.Account, e.Link)
@@ -152,6 +152,19 @@ func listCmd(providers []provider.Provider, st *store.Store, cachePath string, t
var oneLine = strings.NewReplacer("\t", " ", "\r\n", " ", "\n", " ", "\r", " ") var oneLine = strings.NewReplacer("\t", " ", "\r\n", " ", "\n", " ", "\r", " ")
// noteOf is the entry's note, muted, after a note icon (✎ without Nerd
// Font icons) with icon; or "".
func noteOf(e listing.Entry, theme styles.Styles, iconSet icons.Set, icon, color bool) string {
if e.Note == "" {
return ""
}
note := e.Note
if icon {
note = cmp.Or(iconSet.Note, "✎") + " " + note
}
return renderer(color)(theme.Muted, note)
}
// expiryOf says that a secret, key or certificate has expired, in red, // expiryOf says that a secret, key or certificate has expired, in red,
// or when it will if that's within warn (expires in 12d), in yellow, or // or when it will if that's within warn (expires in 12d), in yellow, or
// is "". Its mark (✗, ⚠) is before the name. // is "". Its mark (✗, ⚠) is before the name.
@@ -195,14 +208,13 @@ 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: ✗ in red when something's wrong (it couldn't be // search leaves it out: ✗ in red when something's wrong (it couldn't be
// read, or has expired) or ⚠ when it expires within warn; ★ for a starred // read, or has expired) or ⚠ when it expires within warn; ★ for a starred
// entry and ◷ for one used lately, as the TUI marks them; a note icon // entry and ◷ for one used lately, as the TUI marks them; then the
// (✎ without Nerd Font icons) for one with a note; then the provider's // provider's icon. The marks are right-aligned in room for every kind
// icon. The marks are right-aligned in room for every kind
// turned on, so they sit by the icon and names line up. // 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
stars, recent, notes, expiry, color bool stars, recent, expiry, color bool
warn time.Duration // ui.expiryWarningDays warn time.Duration // ui.expiryWarningDays
now time.Time now time.Time
} }
@@ -232,9 +244,6 @@ func (m marks) of(e listing.Entry) string {
if m.recent { if m.recent {
mark(e.Recent, m.theme.Muted, "◷") mark(e.Recent, m.theme.Muted, "◷")
} }
if m.notes {
mark(e.Note != "", m.theme.Muted, cmp.Or(m.icons.Note, "✎"))
}
pad := strings.Repeat(" ", room-len(parts)) // each mark and its space 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} {
+11 -16
View File
@@ -87,25 +87,20 @@ func TestListExpiry(t *testing.T) {
} }
} }
func TestListNoteMark(t *testing.T) { func TestListNotes(t *testing.T) {
az := icons.NerdFont.Azure e := listing.Entry{Note: "rotate in May"}
m := marks{icons: icons.NerdFont, stars: true, notes: true} if got := noteOf(e, styles.Default(), icons.NerdFont, true, false); got != icons.NerdFont.Note+" rotate in May" {
for _, c := range []struct { t.Errorf("icons: %q", got)
e listing.Entry
want string
}{
{listing.Entry{Provider: "azure", Note: "rotate in May"}, " " + icons.NerdFont.Note + " " + az},
{listing.Entry{Provider: "azure", Note: "x", Starred: true}, " ★ " + icons.NerdFont.Note + " " + az},
{listing.Entry{Provider: "azure"}, " " + az},
} {
if got := m.of(c.e); got != c.want {
t.Errorf("%+v: %q, want %q", c.e, got, c.want)
} }
} if got := noteOf(e, styles.Default(), icons.None, true, false); got != "✎ rotate in May" {
m.icons = icons.None // without Nerd Font icons
if got := m.of(listing.Entry{Provider: "azure", Note: "x"}); got != " ✎" {
t.Errorf("no icons: %q", got) t.Errorf("no icons: %q", got)
} }
if got := noteOf(e, styles.Default(), icons.NerdFont, false, false); got != "rotate in May" {
t.Errorf("--notes=false: %q", got)
}
if got := noteOf(listing.Entry{}, styles.Default(), icons.NerdFont, true, true); got != "" {
t.Errorf("no note: %q", got)
}
} }
func TestListStatusMark(t *testing.T) { func TestListStatusMark(t *testing.T) {