Add a very basic selection mode
This commit is contained in:
parent
ce8f6e0e82
commit
459ab8d739
17
filter.go
17
filter.go
|
@ -38,6 +38,13 @@ var highlight tcell.Style
|
||||||
var selectedStyle tcell.Style
|
var selectedStyle tcell.Style
|
||||||
var helpStyle tcell.Style
|
var helpStyle tcell.Style
|
||||||
|
|
||||||
|
type State struct {
|
||||||
|
Current int
|
||||||
|
InSelectionMode bool
|
||||||
|
UpperBound int
|
||||||
|
LowerBound int
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) {
|
func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) {
|
||||||
|
@ -135,6 +142,8 @@ func main() {
|
||||||
|
|
||||||
lowerBound := 0
|
lowerBound := 0
|
||||||
upperBound := min(ymax-3, len(*input))
|
upperBound := min(ymax-3, len(*input))
|
||||||
|
inSelectedMode := false
|
||||||
|
startOfSelection := 0
|
||||||
|
|
||||||
// Event loop
|
// Event loop
|
||||||
for !done {
|
for !done {
|
||||||
|
@ -189,7 +198,13 @@ func main() {
|
||||||
upperBound = ymax - 2
|
upperBound = ymax - 2
|
||||||
lowerBound = 0
|
lowerBound = 0
|
||||||
currentLine = 0
|
currentLine = 0
|
||||||
|
} else if ev.Key() == tcell.KeyCtrlSpace {
|
||||||
|
if inSelectedMode {
|
||||||
|
toggleItems(input, startOfSelection, currentLine)
|
||||||
|
} else {
|
||||||
|
startOfSelection = currentLine
|
||||||
|
}
|
||||||
|
inSelectedMode = !inSelectedMode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
utils.go
6
utils.go
|
@ -36,6 +36,12 @@ func NewItem(text string) *Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toggleItems(items Items, start int, end int) {
|
||||||
|
for _, item := range (*items)[start:end] {
|
||||||
|
item.Selected = !item.Selected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Pffff Golang, right? :D
|
// Pffff Golang, right? :D
|
||||||
func min(a, b int) int {
|
func min(a, b int) int {
|
||||||
if a < b {
|
if a < b {
|
||||||
|
|
Loading…
Reference in New Issue