package panes import ( "fmt" "github.com/charmbracelet/x/ansi" "git.kebcloud.no/keb/lazysecrets/internal/ui/styles" ) // SourceDetail is the fourth pane on a provider's row: what's known about // its account, one field per row, to move through, filter and copy from. // It's a List, so / filters it like the other panes. type SourceDetail struct { List[Field] } // Field is a row: a value under a label. Info rows (loading, errors) // can't be copied. type Field struct { Label, Value string Info bool } func NewSourceDetail() SourceDetail { l := NewList("", Item[Field]{ ID: func(f Field) string { return f.Label + "\x00" + f.Value }, Filter: func(f Field) string { return f.Value }, // "/tenant" finds the tenant's rows. FilterExtra: func(f Field) string { return f.Label }, Render: func(st styles.Styles, f Field, width int) string { value := f.Value if f.Info { value = st.Muted.Render(value) } return ansi.Truncate(st.Label.Render(fmt.Sprintf("%-10s", f.Label))+" "+value, width, "…") }, }) l.Empty = "nothing known about this account" return SourceDetail{l} } // Set shows fields under title. Another title (another account) starts // over, without a filter. func (s *SourceDetail) Set(title string, fields []Field) { if title != s.Title { s.Reset() s.Title = title } if len(fields) > 0 || len(s.Items()) > 0 { s.SetItems(fields) } } // Shown reports whether there's anything to show. func (s SourceDetail) Shown() bool { return len(s.Items()) > 0 } // Selected is the field under the cursor, unless it's an info row. func (s SourceDetail) Selected() (Field, bool) { f, ok := s.List.Selected() if !ok || f.Info { return Field{}, false } return f, true }