Add dedicated style var for different sections
This commit is contained in:
parent
f2e02756f1
commit
ffca54e997
22
filter.go
22
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue