feat: a Fields pane for anything but a secret, first for Azure accounts: fields and groups to move through, filter and copy #7

Merged
keb merged 5 commits from feat/source-detail into main 2026-10-11 10:37:40 +02:00
5 changed files with 42 additions and 40 deletions
Showing only changes of commit e64748e85d - Show all commits

No files matched your search

+17 -17
View File
@@ -163,9 +163,9 @@ type Model struct {
clip Clipboard clip Clipboard
clipClear time.Duration clipClear time.Duration
openURL func(string) error openURL func(string) error
// srcDetail is the fourth pane on a provider's row, with the groups // fields is the fourth pane for anything but a secret (now: an
// of each provider's account as they load (source_detail.go). // account), with each account's groups as they load (fields.go).
srcDetail panes.SourceDetail fields panes.Fields
groups map[string]groupsState groups map[string]groupsState
getenv func(string) string getenv func(string) string
nvimOpen func(server, path string, line int) error // edit.go nvimOpen func(server, path string, line int) error // edit.go
@@ -361,7 +361,7 @@ func New(providers []provider.Provider, opts Options) Model {
nvimOpen: nvimOpen, nvimOpen: nvimOpen,
cache: newCache(), cache: newCache(),
groups: map[string]groupsState{}, groups: map[string]groupsState{},
srcDetail: panes.NewSourceDetail(), fields: panes.NewFields(),
} }
if m.clip == nil { if m.clip == nil {
m.clip = clipboard.New() m.clip = clipboard.New()
@@ -732,7 +732,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.askHandlerSetup() m.askHandlerSetup()
m.keys.Login.SetEnabled(m.loginFor() != nil) m.keys.Login.SetEnabled(m.loginFor() != nil)
m.detail.SetMessage(m.selectedProblem()) m.detail.SetMessage(m.selectedProblem())
cmds = append(cmds, m.syncSourceDetail()) cmds = append(cmds, m.syncFields())
if m.anyLoading() && !m.spinning { if m.anyLoading() && !m.spinning {
m.spinning = true m.spinning = true
cmds = append(cmds, m.spin.Tick) cmds = append(cmds, m.spin.Tick)
@@ -799,12 +799,12 @@ func (m *Model) handleKey(msg tea.KeyPressMsg) (cmd tea.Cmd, quit bool) {
m.jump(false) m.jump(false)
case key.Matches(msg, k.NextPane): case key.Matches(msg, k.NextPane):
m.focus = (m.focus + 1) % paneCount m.focus = (m.focus + 1) % paneCount
if m.focus == paneContainers && m.srcDetail.Shown() { if m.focus == paneContainers && m.fields.Shown() {
m.focus = paneDetail // an account's row: nothing between m.focus = paneDetail // an account's row: nothing between
} }
case key.Matches(msg, k.PrevPane): case key.Matches(msg, k.PrevPane):
m.focus = (m.focus + paneCount - 1) % paneCount m.focus = (m.focus + paneCount - 1) % paneCount
if m.focus == paneSecrets && m.srcDetail.Shown() { if m.focus == paneSecrets && m.fields.Shown() {
m.focus = paneSources m.focus = paneSources
} }
case key.Matches(msg, k.Pane1): case key.Matches(msg, k.Pane1):
@@ -929,8 +929,8 @@ func (m *Model) focusedFilter() filterable {
case paneSecrets: case paneSecrets:
return &m.secrets return &m.secrets
case paneDetail: case paneDetail:
if m.srcDetail.Shown() { if m.fields.Shown() {
return &m.srcDetail return &m.fields
} }
} }
return nil return nil
@@ -946,8 +946,8 @@ func (m *Model) move(delta int) {
case paneSecrets: case paneSecrets:
m.secrets.Move(delta) m.secrets.Move(delta)
case paneDetail: case paneDetail:
if m.srcDetail.Shown() { if m.fields.Shown() {
m.srcDetail.Move(delta) m.fields.Move(delta)
} else { } else {
m.detail.Scroll(delta) m.detail.Scroll(delta)
} }
@@ -970,10 +970,10 @@ func (m *Model) jump(top bool) {
m.secrets.Top() m.secrets.Top()
case m.focus == paneSecrets: case m.focus == paneSecrets:
m.secrets.Bottom() m.secrets.Bottom()
case m.focus == paneDetail && m.srcDetail.Shown() && top: case m.focus == paneDetail && m.fields.Shown() && top:
m.srcDetail.Top() m.fields.Top()
case m.focus == paneDetail && m.srcDetail.Shown(): case m.focus == paneDetail && m.fields.Shown():
m.srcDetail.Bottom() m.fields.Bottom()
case m.focus == paneDetail && top: case m.focus == paneDetail && top:
m.detail.ScrollTop() m.detail.ScrollTop()
case m.focus == paneDetail: case m.focus == paneDetail:
@@ -1484,7 +1484,7 @@ func (m *Model) copyValue() tea.Cmd {
if a, ok := m.selectedAccount(); ok && a.Copy != "" && m.focus == paneSources { if a, ok := m.selectedAccount(); ok && a.Copy != "" && m.focus == paneSources {
return m.copyText(a.CopyLabel, a.Copy, false) return m.copyText(a.CopyLabel, a.Copy, false)
} }
if f, ok := m.srcDetail.Selected(); ok && m.focus == paneDetail && m.srcDetail.Shown() { if f, ok := m.fields.Selected(); ok && m.focus == paneDetail && m.fields.Shown() {
return m.copyText(fieldName(f), f.Value, false) return m.copyText(fieldName(f), f.Value, false)
} }
return nil return nil
@@ -1612,7 +1612,7 @@ func (m Model) footerView() string {
} else if l != nil && l.Filtering() { } else if l != nil && l.Filtering() {
help = m.helpBar(keys.FilterHelp{Map: m.keys}.ShortHelp(), 2) help = m.helpBar(keys.FilterHelp{Map: m.keys}.ShortHelp(), 2)
} else { } else {
help = m.helpBar(contextHelp{k: m.keys, focus: m.focus, commands: len(m.commandsHere()) > 0, account: m.srcDetail.Shown()}.ShortHelp(), 2) help = m.helpBar(contextHelp{k: m.keys, focus: m.focus, commands: len(m.commandsHere()) > 0, account: m.fields.Shown()}.ShortHelp(), 2)
} }
var lines []string var lines []string
if !m.clipDeadline.IsZero() { if !m.clipDeadline.IsZero() {
@@ -12,9 +12,9 @@ import (
"git.kebcloud.no/keb/lazysecrets/internal/ui/panes" "git.kebcloud.no/keb/lazysecrets/internal/ui/panes"
) )
// On a provider's row, the fourth pane describes its account: the fields // The fourth pane shows Fields for anything but a secret. On a provider's
// the provider knows locally, then the groups the account is in, loaded // row: its account, from what the provider knows locally, then the
// once a session when first shown. // groups the account is in, loaded once a session when first shown.
type groupsState struct { type groupsState struct {
names []string names []string
@@ -28,12 +28,12 @@ type groupsMsg struct {
err error err error
} }
// syncSourceDetail fills the pane for the selected row, loading the // syncFields fills the Fields pane for what's selected, loading an
// account's groups the first time. // account's groups the first time.
func (m *Model) syncSourceDetail() tea.Cmd { func (m *Model) syncFields() tea.Cmd {
acct, ok := m.selectedAccount() acct, ok := m.selectedAccount()
if !ok { if !ok {
m.srcDetail.Set("", nil) m.fields.Set("", nil)
return nil return nil
} }
r, _ := m.sources.Selected() r, _ := m.sources.Selected()
@@ -57,7 +57,7 @@ func (m *Model) syncSourceDetail() tea.Cmd {
} }
fields = append(fields, groupFields(st)...) fields = append(fields, groupFields(st)...)
} }
m.srcDetail.Set(m.byID[r.provider].Label(), fields) m.fields.Set(m.byID[r.provider].Label(), fields)
return cmd return cmd
} }
+1 -1
View File
@@ -36,7 +36,7 @@ type contextHelp struct {
k keys.Map k keys.Map
focus pane focus pane
commands bool // custom commands apply here commands bool // custom commands apply here
account bool // the fourth pane describes an account (source_detail.go) account bool // the fourth pane describes an account (fields.go)
} }
func (c contextHelp) ShortHelp() []key.Binding { func (c contextHelp) ShortHelp() []key.Binding {
+3 -3
View File
@@ -166,7 +166,7 @@ func (m *Model) layout() {
m.containers.SetSize(leftW, h[1]) m.containers.SetSize(leftW, h[1])
m.secrets.SetSize(leftW, h[2]) m.secrets.SetSize(leftW, h[2])
m.detail.SetSize(m.w-leftW, avail) m.detail.SetSize(m.w-leftW, avail)
m.srcDetail.SetSize(m.w-leftW, avail) m.fields.SetSize(m.w-leftW, avail)
} }
// active reports whether p is drawn focused: it has focus and the terminal // active reports whether p is drawn focused: it has focus and the terminal
@@ -181,8 +181,8 @@ func (m Model) panesView() string {
func() string { return m.containers.View(m.st, m.active(paneContainers), spin) }, func() string { return m.containers.View(m.st, m.active(paneContainers), spin) },
func() string { return m.secrets.View(m.st, m.active(paneSecrets), spin) }, func() string { return m.secrets.View(m.st, m.active(paneSecrets), spin) },
func() string { func() string {
if m.srcDetail.Shown() { if m.fields.Shown() {
return m.srcDetail.View(m.st, m.active(paneDetail), spin) return m.fields.View(m.st, m.active(paneDetail), spin)
} }
return m.detail.View(m.st, m.active(paneDetail), spin) return m.detail.View(m.st, m.active(paneDetail), spin)
}, },
@@ -8,10 +8,12 @@ import (
"git.kebcloud.no/keb/lazysecrets/internal/ui/styles" "git.kebcloud.no/keb/lazysecrets/internal/ui/styles"
) )
// SourceDetail is the fourth pane on a provider's row: what's known about // Fields is the fourth pane for anything but a secret (an account, and
// its account, one field per row, to move through, filter and copy from. // what describes vaults, scopes and files): labelled values, one per row,
// It's a List, so / filters it like the other panes. // a label on the first of several values, to move through, filter and
type SourceDetail struct { // copy from. It's a List, so / filters it like the other panes. Secrets
// have Detail, for revealing and versions.
type Fields struct {
List[Field] List[Field]
} }
@@ -22,7 +24,7 @@ type Field struct {
Info bool Info bool
} }
func NewSourceDetail() SourceDetail { func NewFields() Fields {
l := NewList("", Item[Field]{ l := NewList("", Item[Field]{
ID: func(f Field) string { return f.Label + "\x00" + f.Value }, ID: func(f Field) string { return f.Label + "\x00" + f.Value },
Filter: func(f Field) string { return f.Value }, Filter: func(f Field) string { return f.Value },
@@ -36,13 +38,13 @@ func NewSourceDetail() SourceDetail {
return ansi.Truncate(st.Label.Render(fmt.Sprintf("%-10s", f.Label))+" "+value, width, "…") return ansi.Truncate(st.Label.Render(fmt.Sprintf("%-10s", f.Label))+" "+value, width, "…")
}, },
}) })
l.Empty = "nothing known about this account" l.Empty = "nothing to show"
return SourceDetail{l} return Fields{l}
} }
// Set shows fields under title. Another title (another account) starts // Set shows fields under title. Another title (another account or vault)
// over, without a filter. // starts over, without a filter.
func (s *SourceDetail) Set(title string, fields []Field) { func (s *Fields) Set(title string, fields []Field) {
if title != s.Title { if title != s.Title {
s.Reset() s.Reset()
s.Title = title s.Title = title
@@ -53,10 +55,10 @@ func (s *SourceDetail) Set(title string, fields []Field) {
} }
// Shown reports whether there's anything to show. // Shown reports whether there's anything to show.
func (s SourceDetail) Shown() bool { return len(s.Items()) > 0 } func (s Fields) Shown() bool { return len(s.Items()) > 0 }
// Selected is the field under the cursor, unless it's an info row. // Selected is the field under the cursor, unless it's an info row.
func (s SourceDetail) Selected() (Field, bool) { func (s Fields) Selected() (Field, bool) {
f, ok := s.List.Selected() f, ok := s.List.Selected()
if !ok || f.Info { if !ok || f.Info {
return Field{}, false return Field{}, false