Simon Kellet 9 months ago
parent e6dbadb3d5
commit 3c12d8010a
  1. 2
      README.md
  2. 8
      go.mod
  3. 4
      go.sum
  4. 99
      main.go
  5. BIN
      todo-app

@ -0,0 +1,2 @@
# TODO app in Go using ncurses
Very simple app

@ -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
)

@ -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=

@ -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()
}

Binary file not shown.
Loading…
Cancel
Save