From 13aebe27ff70d47fdfa8323d690f60e97225ffb3 Mon Sep 17 00:00:00 2001 From: Caleb Foust Date: Thu, 1 Feb 2024 06:21:00 +0800 Subject: [PATCH] feat: max height for table rows --- pkg/fuzzy/view.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/pkg/fuzzy/view.go b/pkg/fuzzy/view.go index 12df5258..571a0ee9 100644 --- a/pkg/fuzzy/view.go +++ b/pkg/fuzzy/view.go @@ -115,10 +115,12 @@ func (f *Fuzzy) renderPreview(state *tty.State) { } func (f *Fuzzy) renderOptions(common, prompt lipgloss.Style, maxOptions int) string { - inactive := common.Copy(). + rowStyle := common.Copy(). + MaxHeight(1) + inactive := rowStyle.Copy(). Background(lipgloss.Color("#968C83")). Foreground(lipgloss.Color("#20111B")) - active := common.Copy(). + active := rowStyle.Copy(). Background(lipgloss.Color("#E8E3DF")). Foreground(lipgloss.Color("#20111B")) @@ -147,13 +149,24 @@ func (f *Fuzzy) renderOptions(common, prompt lipgloss.Style, maxOptions int) str ) windowEnd := geom.Min(len(options), windowOffset+maxOptions) - for _, option := range options[windowOffset:windowEnd] { - if len(option.Columns) == 0 { - rows = append(rows, []string{option.Text}) - continue + for index, option := range options[windowOffset:windowEnd] { + columns := append( + []string{}, + option.Columns..., + ) + + if len(columns) == 0 { + columns = []string{option.Text} + } + + // Add in the > in front of each row + prefix := " " + if windowOffset+index == f.selected { + prefix = "> " } + columns[0] = prefix + columns[0] - rows = append(rows, option.Columns) + rows = append(rows, columns) } lines := strings.Split(table.New().