package main import ( "fmt" "log" "git.yetaga.in/alazyreader/library/config" "git.yetaga.in/alazyreader/library/ui" "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 := ui.NewList([]string{"foo", "bar", "baz"}, 0) menu := ui.NewBox( "library", []string{"(e)dit", "(q)uit"}, ui.Contents{{ Offsets: ui.Offsets{Top: 1, Left: 2, Bottom: -2, Right: -2}, Container: l, }}, ) activeBook := ui.NewBox( "book", []string{"test"}, ui.Contents{}, ) container := ui.NewContainer( ui.Contents{{Container: menu}, {Container: activeBook}}, ui.LayoutHorizontalEven, ) // init screen.Clear() w, h := screen.Size() container.SetSize(0, 0, h, w) container.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.SetSelected(l.Selected() - 1) } if v.Key() == tcell.KeyDown && l.Selected() < len(l.ListMembers())-1 { l.SetSelected(l.Selected() + 1) } if v.Rune() == 'q' { screen.Fini() fmt.Printf("Thank you for playing Wing Commander!\n\n") return } screen.Clear() container.Draw(screen) case *tcell.EventResize: // screen redraw w, h := screen.Size() container.SetSize(0, 0, h, w) screen.Clear() container.Draw(screen) case *tcell.EventInterrupt: case *tcell.EventMouse: case *tcell.EventTime: default: } screen.Show() // repaint } }