feat: lazysecrets list right-aligns the marks by the icon, so names line up
This commit is contained in:
2 files changed
+16
-9
No files matched your search
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user