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.
|
// TODO: Make the highlight style configuratble.
|
||||||
// The style to be used with the current line
|
// The style to be used with the current line
|
||||||
var highlight tcell.Style
|
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
|
// Draws the given `text` to the screen `s` at the given coordinates. Remember that
|
||||||
// the text will be wrapped if it overflow.
|
// 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.
|
// Main render function that gets called during the event loop.
|
||||||
func Render(s tcell.Screen, inputs Items, lowerBound int, upperBound int, current int) {
|
func Render(s tcell.Screen, inputs Items, lowerBound int, upperBound int, current int) {
|
||||||
y := 2
|
y := 2
|
||||||
status := fmt.Sprintf("Navigation: [UP or C-p] [Down or C-n] Select: SPACE Cancel: [q ESC] Done: [Enter] Line: %d", current)
|
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)
|
drawText(s, 0, 0, xmax-1, 1, helpStyle, status)
|
||||||
for i, item := range (*inputs)[lowerBound:upperBound] {
|
for i, item := range (*inputs)[lowerBound:upperBound] {
|
||||||
style := tcell.StyleDefault
|
style := tcell.StyleDefault
|
||||||
var txt string
|
var txt string
|
||||||
|
|
||||||
if current == lowerBound+i {
|
if item.Selected {
|
||||||
style = highlight
|
txt = fmt.Sprintf(" X %s", item.Text)
|
||||||
|
style = selectedStyle
|
||||||
|
} else {
|
||||||
|
txt = fmt.Sprintf(" %s", item.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.Selected {
|
if current == lowerBound+i {
|
||||||
txt = fmt.Sprintf("XXXX | %s", item.Text)
|
style = highlight
|
||||||
} else {
|
|
||||||
txt = fmt.Sprintf("%04d | %s", lowerBound+i, item.Text)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drawText(s, 0, y, xmax-1, y+1, style, txt)
|
drawText(s, 0, y, xmax-1, y+1, style, txt)
|
||||||
|
@ -84,6 +87,9 @@ func main() {
|
||||||
// TODO: Make the default style configurable
|
// TODO: Make the default style configurable
|
||||||
defStyle := tcell.StyleDefault.Background(tcell.ColorDefault).Foreground(tcell.ColorDefault)
|
defStyle := tcell.StyleDefault.Background(tcell.ColorDefault).Foreground(tcell.ColorDefault)
|
||||||
highlight = tcell.StyleDefault.Background(tcell.ColorDarkGray).Foreground(tcell.ColorWhite)
|
highlight = tcell.StyleDefault.Background(tcell.ColorDarkGray).Foreground(tcell.ColorWhite)
|
||||||
|
selectedStyle = tcell.StyleDefault.Foreground(tcell.ColorYellow)
|
||||||
|
helpStyle = tcell.StyleDefault.Foreground(tcell.ColorDefault)
|
||||||
|
|
||||||
currentLine := 0
|
currentLine := 0
|
||||||
done := false
|
done := false
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue