diff --git a/help/help.go b/help/help.go index c26f046..b499ac9 100644 --- a/help/help.go +++ b/help/help.go @@ -75,7 +75,6 @@ func DefaultLightStyles() Styles { // Model contains the state of the help view. type Model struct { - Width int ShowAll bool // if true, render the "full" help menu ShortSeparator string @@ -86,6 +85,8 @@ type Model struct { Ellipsis string Styles Styles + + width int } // New creates a new help view with some useful defaults. @@ -111,6 +112,16 @@ func (m Model) View(k KeyMap) string { return m.ShortHelpView(k.ShortHelp()) } +// SetWidth sets the maximum width for the help view. +func (m *Model) SetWidth(w int) { + m.width = w +} + +// Width returns the maximum width for the help view. +func (m Model) Width() int { + return m.width +} + // ShortHelpView renders a single line help view from a slice of keybindings. // If the line is longer than the maximum width it will be gracefully // truncated, showing only as many help items as possible. @@ -223,10 +234,10 @@ func (m Model) FullHelpView(groups [][]key.Binding) string { func (m Model) shouldAddItem(totalWidth, width int) (tail string, ok bool) { // If there's room for an ellipsis, print that. - if m.Width > 0 && totalWidth+width > m.Width { + if m.width > 0 && totalWidth+width > m.width { tail = " " + m.Styles.Ellipsis.Inline(true).Render(m.Ellipsis) - if totalWidth+lipgloss.Width(tail) < m.Width { + if totalWidth+lipgloss.Width(tail) < m.width { return tail, false } } diff --git a/help/help_test.go b/help/help_test.go index a03217c..fbb5e26 100644 --- a/help/help_test.go +++ b/help/help_test.go @@ -30,7 +30,7 @@ func TestFullHelp(t *testing.T) { for _, w := range []int{20, 30, 40} { t.Run(fmt.Sprintf("full help %d width", w), func(t *testing.T) { - m.Width = w + m.SetWidth(w) s := m.FullHelpView(kb) s = ansi.Strip(s) golden.RequireEqual(t, []byte(s)) diff --git a/list/list.go b/list/list.go index fb87b0f..f5338d0 100644 --- a/list/list.go +++ b/list/list.go @@ -697,7 +697,7 @@ func (m *Model) SetSize(width, height int) { m.width = width m.height = height - m.Help.Width = width + m.Help.SetWidth(width) m.FilterInput.SetWidth(width - promptWidth - lipgloss.Width(m.spinnerView())) m.updatePagination() m.updateKeybindings()