mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Can: - move between todo items - toggle checked/unchecked state Cannot: - persiste changes to file - add items - delete items
45 lines
762 B
Go
45 lines
762 B
Go
package todo
|
|
|
|
import ()
|
|
|
|
type List struct {
|
|
Items []*Item
|
|
|
|
selected int
|
|
}
|
|
|
|
func (list *List) Len() int {
|
|
return len(list.Items)
|
|
}
|
|
|
|
func (list *List) Less(i, j int) bool {
|
|
return list.Items[i].Index < list.Items[j].Index
|
|
}
|
|
|
|
func (list *List) Swap(i, j int) {
|
|
list.Items[i], list.Items[j] = list.Items[j], list.Items[i]
|
|
}
|
|
|
|
func (list *List) Next() {
|
|
list.selected = list.selected + 1
|
|
if list.selected >= len(list.Items) {
|
|
list.selected = 0
|
|
}
|
|
}
|
|
|
|
func (list *List) Prev() {
|
|
list.selected = list.selected - 1
|
|
if list.selected < 0 {
|
|
list.selected = len(list.Items) - 1
|
|
}
|
|
}
|
|
|
|
// Toggle switches the checked state of the selected item
|
|
func (list *List) Toggle() {
|
|
list.Items[list.selected].Toggle()
|
|
}
|
|
|
|
func (list *List) Unselect() {
|
|
list.selected = -1
|
|
}
|