init
This commit is contained in:
parent
e6dbadb3d5
commit
3c12d8010a
8
go.mod
Normal file
8
go.mod
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
module todo-app
|
||||||
|
|
||||||
|
go 1.21.3
|
||||||
|
|
||||||
|
require (
|
||||||
|
golang.org/x/sys v0.0.0-20210317225723-c4fcb01b228e // indirect
|
||||||
|
seehuhn.de/go/ncurses v0.2.0 // indirect
|
||||||
|
)
|
4
go.sum
Normal file
4
go.sum
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
golang.org/x/sys v0.0.0-20210317225723-c4fcb01b228e h1:XNp2Flc/1eWQGk5BLzqTAN7fQIwIbfyVTuVxXxZh73M=
|
||||||
|
golang.org/x/sys v0.0.0-20210317225723-c4fcb01b228e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
seehuhn.de/go/ncurses v0.2.0 h1:ZV256n0GIMVEHJnECliGMffzdFsEoT7krJqdfGoYD1E=
|
||||||
|
seehuhn.de/go/ncurses v0.2.0/go.mod h1:oAc9Y+UN0tflNV0iME++z0ij9uNmIjdxQFkpGoRMd2E=
|
99
main.go
Normal file
99
main.go
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"seehuhn.de/go/ncurses"
|
||||||
|
)
|
||||||
|
|
||||||
|
const MAX_TODOS = 3
|
||||||
|
|
||||||
|
type item struct {
|
||||||
|
desc string
|
||||||
|
done bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func make_x(isDone bool) string {
|
||||||
|
s := ""
|
||||||
|
switch isDone {
|
||||||
|
case true:
|
||||||
|
s = "x"
|
||||||
|
case false:
|
||||||
|
s = " "
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
hasQuit := false
|
||||||
|
currTodo := 0
|
||||||
|
|
||||||
|
todos := []item{
|
||||||
|
{
|
||||||
|
"Make TODO app",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Make coffee",
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Shit the bed",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Make a cup of tea",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init window
|
||||||
|
win := ncurses.Init()
|
||||||
|
defer ncurses.EndWin()
|
||||||
|
ncurses.CursSet(ncurses.CursorOff)
|
||||||
|
|
||||||
|
for !hasQuit {
|
||||||
|
win.Erase()
|
||||||
|
win.Println("TODO:")
|
||||||
|
win.Println("----------------------")
|
||||||
|
for index, item := range todos {
|
||||||
|
if currTodo == index {
|
||||||
|
win.AttrOn(ncurses.AttrStandout)
|
||||||
|
win.Printf("[%s]", make_x(item.done))
|
||||||
|
win.Printf(" %s", item.desc)
|
||||||
|
win.Println("")
|
||||||
|
win.AttrOff(ncurses.AttrStandout)
|
||||||
|
} else {
|
||||||
|
win.AttrOn(ncurses.AttrNormal)
|
||||||
|
win.Printf("[%s]", make_x(item.done))
|
||||||
|
win.Printf(" %s", item.desc)
|
||||||
|
win.Println("")
|
||||||
|
win.AttrOff(ncurses.AttrNormal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ch := win.GetCh()
|
||||||
|
switch ch {
|
||||||
|
|
||||||
|
case ncurses.KeyUp:
|
||||||
|
if currTodo == 0 {
|
||||||
|
currTodo = 0
|
||||||
|
} else {
|
||||||
|
currTodo -= 1
|
||||||
|
}
|
||||||
|
|
||||||
|
case ncurses.KeyDown:
|
||||||
|
if currTodo >= len(todos)-1 {
|
||||||
|
currTodo = len(todos) - 1
|
||||||
|
} else {
|
||||||
|
currTodo += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
case ' ':
|
||||||
|
todos[currTodo].done = !todos[currTodo].done
|
||||||
|
|
||||||
|
case 'q':
|
||||||
|
hasQuit = !hasQuit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
win.Refresh()
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user