feat: the logo on top of the status pane, as text further down #18

Merged
keb merged 2 commits from feat/logo into main 2026-10-11 14:29:38 +02:00
3 changed files with 50 additions and 20 deletions
Showing only changes of commit d9de14f926 - Show all commits

No files matched your search

+2 -2
View File
@@ -50,7 +50,7 @@ func (m *Model) syncFields() tea.Cmd {
m.fields.Hide() m.fields.Hide()
return nil return nil
} }
m.fields.Header = nil m.fields.Header, m.fields.HeaderShort = nil, ""
switch m.detailOf() { switch m.detailOf() {
case paneSources: case paneSources:
r, ok := m.sources.Selected() r, ok := m.sources.Selected()
@@ -69,7 +69,7 @@ func (m *Model) syncFields() tea.Cmd {
m.fields.Show("", nil) m.fields.Show("", nil)
} }
case paneStatus: case paneStatus:
m.fields.Header = logo m.fields.Header, m.fields.HeaderShort = logo, strings.TrimSpace("lazysecrets "+m.versionLabel())
m.fields.Show("lazysecrets", m.statusFields()) m.fields.Show("lazysecrets", m.statusFields())
case paneContainers: case paneContainers:
if c, ok := m.containers.Selected(); ok { if c, ok := m.containers.Selected(); ok {
+24 -18
View File
@@ -37,9 +37,11 @@ type List[T any] struct {
// Age says how old the items are ("2h ago") while they reload, by // Age says how old the items are ("2h ago") while they reload, by
// the counter. // the counter.
Age string Age string
// Header lines (a logo) go above the items, when the pane has room // Header lines (a logo) go above the items while the cursor is in
// for them and there's no filter. // the rows under it, the pane has room and there's no filter; else
Header []string // HeaderShort, a line of plain text, does.
Header []string
HeaderShort string
item Item[T] item Item[T]
items []T items []T
@@ -166,27 +168,34 @@ func (l List[T]) rows() int {
if l.filtering { if l.filtering {
r-- r--
} }
if l.headerShown() { r -= len(l.header())
r -= len(l.Header) + 1
}
return max(0, r) return max(0, r)
} }
// headerMinRows is how many item rows the header leaves at least. // headerMinRows is how many item rows Header leaves at least.
const headerMinRows = 5 const headerMinRows = 5
// headerShown reports whether Header fits: as wide as the pane allows, // header is the lines above the items: Header and a blank line, if it
// leaving headerMinRows, a blank line under it, and no filter. // fits, leaves headerMinRows and the cursor is in the rows under it;
func (l List[T]) headerShown() bool { // else HeaderShort.
func (l List[T]) header() []string {
short := []string{}
if l.HeaderShort != "" {
short = []string{l.HeaderShort}
}
if len(l.Header) == 0 || l.filtering || l.input.Value() != "" { if len(l.Header) == 0 || l.filtering || l.input.Value() != "" {
return false return short
} }
for _, line := range l.Header { for _, line := range l.Header {
if ansi.StringWidth(line) > l.w-3 { if ansi.StringWidth(line) > l.w-3 {
return false return short
} }
} }
return l.h-2-len(l.Header)-1 >= headerMinRows below := l.h - 2 - len(l.Header) - 1
if below < headerMinRows || l.cursor >= below {
return short
}
return append(l.Header[:len(l.Header):len(l.Header)], "")
} }
// Filtering reports whether the filter input has focus. // Filtering reports whether the filter input has focus.
@@ -352,11 +361,8 @@ func (l List[T]) View(st styles.Styles, focused bool, spin string) string {
if l.filtering { if l.filtering {
body = append(body, l.input.View()) body = append(body, l.input.View())
} }
if l.headerShown() { for _, line := range l.header() {
for _, line := range l.Header { body = append(body, st.Notice.Render(" "+line))
body = append(body, st.Notice.Render(" "+line))
}
body = append(body, "")
} }
switch { switch {
+24
View File
@@ -177,3 +177,27 @@ func TestHighlightKeepsColours(t *testing.T) {
t.Error("reverse kept the colours") t.Error("reverse kept the colours")
} }
} }
func TestListHeader(t *testing.T) {
l := NewList("t", Item[string]{
ID: func(s string) string { return s },
Filter: func(s string) string { return s },
Render: func(_ styles.Styles, s string, _ int) string { return s },
})
l.Header, l.HeaderShort = []string{"ART1", "ART2"}, "short"
l.SetItems([]string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"})
l.SetSize(30, 2+2+1+6) // the art, a blank line and 6 rows
st := styles.Default()
if v := l.View(st, true, ""); !strings.Contains(v, "ART1") || strings.Contains(v, "short") {
t.Errorf("at the top, the art:\n%s", v)
}
l.Move(6) // below the rows under the art
if v := l.View(st, true, ""); strings.Contains(v, "ART1") || !strings.Contains(v, "short") || !strings.Contains(v, " g") {
t.Errorf("further down, the text:\n%s", v)
}
l.Top()
l.SetSize(30, 8) // too short for the art and 5 rows
if v := l.View(st, true, ""); strings.Contains(v, "ART1") || !strings.Contains(v, "short") {
t.Errorf("no room, the text:\n%s", v)
}
}