Skip to content

Commit

Permalink
feat: max height for table rows
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Jan 31, 2024
1 parent e96410f commit 13aebe2
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions pkg/fuzzy/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down Expand Up @@ -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().
Expand Down

0 comments on commit 13aebe2

Please sign in to comment.