@@ -75,7 +75,6 @@ func DefaultLightStyles() Styles {
7575
7676// Model contains the state of the help view.
7777type Model struct {
78- Width int
7978 ShowAll bool // if true, render the "full" help menu
8079
8180 ShortSeparator string
@@ -86,6 +85,8 @@ type Model struct {
8685 Ellipsis string
8786
8887 Styles Styles
88+
89+ width int
8990}
9091
9192// New creates a new help view with some useful defaults.
@@ -111,6 +112,16 @@ func (m Model) View(k KeyMap) string {
111112 return m .ShortHelpView (k .ShortHelp ())
112113}
113114
115+ // SetWidth sets the maximum width for the help view.
116+ func (m * Model ) SetWidth (w int ) {
117+ m .width = w
118+ }
119+
120+ // Width returns the maximum width for the help view.
121+ func (m Model ) Width () int {
122+ return m .width
123+ }
124+
114125// ShortHelpView renders a single line help view from a slice of keybindings.
115126// If the line is longer than the maximum width it will be gracefully
116127// truncated, showing only as many help items as possible.
@@ -223,10 +234,10 @@ func (m Model) FullHelpView(groups [][]key.Binding) string {
223234
224235func (m Model ) shouldAddItem (totalWidth , width int ) (tail string , ok bool ) {
225236 // If there's room for an ellipsis, print that.
226- if m .Width > 0 && totalWidth + width > m .Width {
237+ if m .width > 0 && totalWidth + width > m .width {
227238 tail = " " + m .Styles .Ellipsis .Inline (true ).Render (m .Ellipsis )
228239
229- if totalWidth + lipgloss .Width (tail ) < m .Width {
240+ if totalWidth + lipgloss .Width (tail ) < m .width {
230241 return tail , false
231242 }
232243 }
0 commit comments