library/cmd/manage/main.go

77 lines
1.4 KiB
Go

package main
import (
"fmt"
"log"
"git.yetaga.in/alazyreader/library/config"
"github.com/gdamore/tcell"
"github.com/kelseyhightower/envconfig"
)
func main() {
var c config.Config
err := envconfig.Process("library", &c)
if err != nil {
log.Fatalln(err)
}
screen, err := tcell.NewScreen()
if err != nil {
log.Fatalln(err)
}
err = screen.Init()
if err != nil {
log.Fatalln(err)
}
l := NewList([]string{"foo", "bar", "baz"}, 0)
b := NewBox(
"library",
[]string{"(e)dit", "(q)uit"},
contents{{
offsets: offsets{top: 1, left: 2, bottom: -2, right: -2},
container: l,
}},
)
// init
screen.Clear()
w, h := screen.Size()
b.SetSize(0, 0, h, w)
b.Draw(screen)
screen.Sync()
// UI loop
for {
e := screen.PollEvent()
switch v := e.(type) {
case *tcell.EventError:
screen.Beep()
case *tcell.EventKey: // input handling
if v.Key() == tcell.KeyUp && l.selected > 0 {
l.selected = l.selected - 1
}
if v.Key() == tcell.KeyDown && l.selected < len(l.listItems)-1 {
l.selected = l.selected + 1
}
if v.Rune() == 'q' {
screen.Fini()
fmt.Printf("Thank you for playing Wing Commander!\n\n")
return
}
screen.Clear()
b.Draw(screen)
case *tcell.EventResize: // screen redraw
w, h := screen.Size()
b.SetSize(0, 0, h, w)
screen.Clear()
b.Draw(screen)
case *tcell.EventInterrupt:
case *tcell.EventMouse:
case *tcell.EventTime:
default:
}
screen.Sync() // repaint
}
}