start to make it a little real...
This commit is contained in:
parent
b648c1c0ae
commit
117c7e0e41
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.yetaga.in/alazyreader/library/config"
|
"git.yetaga.in/alazyreader/library/config"
|
||||||
@ -24,39 +25,58 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
screen.Clear()
|
screen.Clear()
|
||||||
inc := 0
|
w, h := screen.Size()
|
||||||
|
l := &list{
|
||||||
|
w: w - 4, h: h - 4,
|
||||||
|
x: 2, y: 1,
|
||||||
|
selected: 2,
|
||||||
|
listItems: []string{"foo", "bar", "baz"},
|
||||||
|
}
|
||||||
|
b := &box{
|
||||||
|
w: w, h: h,
|
||||||
|
x: 0, y: 0,
|
||||||
|
title: "library",
|
||||||
|
menuItems: []string{"(e)dit", "(q)uit"},
|
||||||
|
contents: l,
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
e := screen.PollEvent()
|
e := screen.PollEvent()
|
||||||
screen.Clear()
|
|
||||||
w, h := screen.Size()
|
|
||||||
b := &box{h: h, w: w, x: 0, y: 0, title: "library", menuItems: []string{"(e)dit", "(q)uit"}}
|
|
||||||
switch v := e.(type) {
|
switch v := e.(type) {
|
||||||
case *tcell.EventError:
|
case *tcell.EventError:
|
||||||
|
screen.Clear()
|
||||||
screen.Beep()
|
screen.Beep()
|
||||||
b.draw(screen)
|
b.draw(screen)
|
||||||
screen.SetContent(1, 1, 'E', nil, tcell.StyleDefault)
|
screen.SetContent(1, 1, 'E', nil, tcell.StyleDefault)
|
||||||
case *tcell.EventInterrupt:
|
|
||||||
b.draw(screen)
|
|
||||||
screen.Sync()
|
|
||||||
case *tcell.EventKey:
|
case *tcell.EventKey:
|
||||||
inc += 1
|
screen.Clear()
|
||||||
b.draw(screen)
|
if v.Key() == tcell.KeyUp && l.selected > 0 {
|
||||||
screen.SetContent(1, 1, v.Rune(), nil, tcell.StyleDefault)
|
l.selected = l.selected - 1
|
||||||
screen.SetContent(2, 2, rune(inc+48), nil, tcell.StyleDefault)
|
}
|
||||||
|
if v.Key() == tcell.KeyDown && l.selected < len(l.listItems)-1 {
|
||||||
|
l.selected = l.selected + 1
|
||||||
|
}
|
||||||
if v.Rune() == 'q' {
|
if v.Rune() == 'q' {
|
||||||
screen.Fini()
|
screen.Fini()
|
||||||
|
fmt.Printf("Thank you for playing Wing Commander!\n\n")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
screen.Sync()
|
|
||||||
case *tcell.EventMouse:
|
|
||||||
continue
|
|
||||||
case *tcell.EventResize:
|
|
||||||
b.draw(screen)
|
b.draw(screen)
|
||||||
screen.Sync()
|
case *tcell.EventResize:
|
||||||
|
screen.Clear()
|
||||||
|
w, h := screen.Size()
|
||||||
|
b.w, b.h = w, h
|
||||||
|
b.draw(screen)
|
||||||
|
case *tcell.EventInterrupt:
|
||||||
|
case *tcell.EventMouse:
|
||||||
case *tcell.EventTime:
|
case *tcell.EventTime:
|
||||||
continue
|
default:
|
||||||
|
}
|
||||||
|
screen.Sync()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type drawable interface {
|
||||||
|
draw(tcell.Screen)
|
||||||
}
|
}
|
||||||
|
|
||||||
type box struct {
|
type box struct {
|
||||||
@ -64,6 +84,7 @@ type box struct {
|
|||||||
h, w int
|
h, w int
|
||||||
title string
|
title string
|
||||||
menuItems []string
|
menuItems []string
|
||||||
|
contents drawable
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *box) draw(s tcell.Screen) {
|
func (b *box) draw(s tcell.Screen) {
|
||||||
@ -103,4 +124,25 @@ func (b *box) draw(s tcell.Screen) {
|
|||||||
t++
|
t++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if b.contents != nil {
|
||||||
|
b.contents.draw(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type list struct {
|
||||||
|
x, y int
|
||||||
|
h, w int
|
||||||
|
selected int
|
||||||
|
listItems []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *list) draw(s tcell.Screen) {
|
||||||
|
for i := range l.listItems {
|
||||||
|
for j, r := range l.listItems[i] {
|
||||||
|
s.SetContent(l.x+j, l.y+i, r, nil, tcell.StyleDefault)
|
||||||
|
}
|
||||||
|
if i == l.selected {
|
||||||
|
s.SetContent(l.x+len(l.listItems[i])+1, l.y+i, '<', nil, tcell.StyleDefault)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user