diff options
| author | Paul Bütow <1224732+snonux@users.noreply.github.com> | 2025-06-20 18:35:48 +0300 |
|---|---|---|
| committer | Paul Bütow <1224732+snonux@users.noreply.github.com> | 2025-06-20 18:35:48 +0300 |
| commit | e12c3213df812fdc0b21eba3d918c68b05d2502a (patch) | |
| tree | b4400c158e6924f51866aceee266dab36ba7d54d /internal/atable/table.go | |
| parent | 20417e3024916a23a0378f72c1336ccbb56f0bae (diff) | |
Add option to hide headers
Diffstat (limited to 'internal/atable/table.go')
| -rw-r--r-- | internal/atable/table.go | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/internal/atable/table.go b/internal/atable/table.go index 5e74864..d6ea99d 100644 --- a/internal/atable/table.go +++ b/internal/atable/table.go @@ -17,12 +17,13 @@ type Model struct { KeyMap KeyMap Help help.Model - cols []Column - rows []Row - cursor int - colCursor int - focus bool - styles Styles + cols []Column + rows []Row + cursor int + colCursor int + focus bool + styles Styles + showHeaders bool viewport viewport.Model start int @@ -149,9 +150,10 @@ func New(opts ...Option) Model { colCursor: 0, viewport: viewport.New(0, 20), //nolint:mnd - KeyMap: DefaultKeyMap(), - Help: help.New(), - styles: DefaultStyles(), + KeyMap: DefaultKeyMap(), + Help: help.New(), + styles: DefaultStyles(), + showHeaders: true, } for _, opt := range opts { @@ -212,6 +214,13 @@ func WithKeyMap(km KeyMap) Option { } } +// WithShowHeaders controls rendering of table headers. +func WithShowHeaders(show bool) Option { + return func(m *Model) { + m.showHeaders = show + } +} + // Update is the Bubble Tea update loop. func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { if !m.focus { @@ -267,7 +276,11 @@ func (m *Model) Blur() { // View renders the component. func (m Model) View() string { - return m.headersView() + "\n" + m.viewport.View() + headers := m.headersView() + if headers == "" { + return m.viewport.View() + } + return headers + "\n" + m.viewport.View() } // HelpView is a helper method for rendering the help menu from the keymap. @@ -447,6 +460,9 @@ func (m *Model) FromValues(value, separator string) { } func (m Model) headersView() string { + if !m.showHeaders { + return "" + } s := make([]string, 0, len(m.cols)) for _, col := range m.cols { if col.Width <= 0 { |
