From ffca54e997abdacf9ad2a2676112a04fc11137b6 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Wed, 23 Nov 2022 22:31:30 +0000 Subject: [PATCH] Add dedicated style var for different sections --- filter.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/filter.go b/filter.go index afd8151..7f0e130 100644 --- a/filter.go +++ b/filter.go @@ -32,6 +32,8 @@ var ymax int // TODO: Make the highlight style configuratble. // The style to be used with the current line var highlight tcell.Style +var selectedStyle tcell.Style +var helpStyle tcell.Style // Draws the given `text` to the screen `s` at the given coordinates. Remember that // the text will be wrapped if it overflow. @@ -54,20 +56,21 @@ func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string // Main render function that gets called during the event loop. func Render(s tcell.Screen, inputs Items, lowerBound int, upperBound int, current int) { y := 2 - status := fmt.Sprintf("Navigation: [UP or C-p] [Down or C-n] Select: SPACE Cancel: [q ESC] Done: [Enter] Line: %d", current) - drawText(s, 0, 0, xmax-1, 1, tcell.StyleDefault, status) + status := fmt.Sprintf("Navigation: [UP or C-p] [Down or C-n] | Select: SPACE | Cancel: [q ESC] | Done: [Enter] | Line: %d", current) + drawText(s, 0, 0, xmax-1, 1, helpStyle, status) for i, item := range (*inputs)[lowerBound:upperBound] { style := tcell.StyleDefault var txt string - if current == lowerBound+i { - style = highlight + if item.Selected { + txt = fmt.Sprintf(" X %s", item.Text) + style = selectedStyle + } else { + txt = fmt.Sprintf(" %s", item.Text) } - if item.Selected { - txt = fmt.Sprintf("XXXX | %s", item.Text) - } else { - txt = fmt.Sprintf("%04d | %s", lowerBound+i, item.Text) + if current == lowerBound+i { + style = highlight } drawText(s, 0, y, xmax-1, y+1, style, txt) @@ -84,6 +87,9 @@ func main() { // TODO: Make the default style configurable defStyle := tcell.StyleDefault.Background(tcell.ColorDefault).Foreground(tcell.ColorDefault) highlight = tcell.StyleDefault.Background(tcell.ColorDarkGray).Foreground(tcell.ColorWhite) + selectedStyle = tcell.StyleDefault.Foreground(tcell.ColorYellow) + helpStyle = tcell.StyleDefault.Foreground(tcell.ColorDefault) + currentLine := 0 done := false