Add a very basic selection mode

This commit is contained in:
Sameer Rahmani 2022-11-25 13:51:30 +00:00
parent ce8f6e0e82
commit 459ab8d739
2 changed files with 22 additions and 1 deletions

View File

@ -38,6 +38,13 @@ var highlight tcell.Style
var selectedStyle 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
// the text will be wrapped if it overflow.
func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) {
@ -135,6 +142,8 @@ func main() {
lowerBound := 0
upperBound := min(ymax-3, len(*input))
inSelectedMode := false
startOfSelection := 0
// Event loop
for !done {
@ -189,7 +198,13 @@ func main() {
upperBound = ymax - 2
lowerBound = 0
currentLine = 0
} else if ev.Key() == tcell.KeyCtrlSpace {
if inSelectedMode {
toggleItems(input, startOfSelection, currentLine)
} else {
startOfSelection = currentLine
}
inSelectedMode = !inSelectedMode
}
}
}

View File

@ -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
func min(a, b int) int {
if a < b {