From 9e97b0841b96013cfde8b0e9524389031a01312c Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Mon, 23 May 2022 22:43:35 -0300 Subject: [PATCH] feat: allow to set the height of the item The user might want to show more than 2 lines, and, right now, if they try to do so, things break. Signed-off-by: Carlos A Becker --- list/defaultitem.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/list/defaultitem.go b/list/defaultitem.go index 04dfe7b9..9e0d5487 100644 --- a/list/defaultitem.go +++ b/list/defaultitem.go @@ -86,6 +86,7 @@ type DefaultDelegate struct { UpdateFunc func(tea.Msg, *Model) tea.Cmd ShortHelpFunc func() []key.Binding FullHelpFunc func() [][]key.Binding + height int spacing int } @@ -94,14 +95,22 @@ func NewDefaultDelegate() DefaultDelegate { return DefaultDelegate{ ShowDescription: true, Styles: NewDefaultItemStyles(), + height: 2, spacing: 1, } } +// SetHeight sets delegate's preferred height. +func (d *DefaultDelegate) SetHeight(i int) { + d.height = i +} + // Height returns the delegate's preferred height. +// This has effect only if ShowDescription is true, +// otherwise height is always 1. func (d DefaultDelegate) Height() int { if d.ShowDescription { - return 2 //nolint:gomnd + return d.height } return 1 }