cleaning up some status bar cruft

master
Jordan Orelli 4 years ago
parent 15f6b0acfb
commit 8ab25870d0

@ -9,16 +9,15 @@ import (
type statusBar struct { type statusBar struct {
inFocus bool inFocus bool
ui *UI msgCount int
showCount int
clearCount int
} }
func (s *statusBar) handleEvent(ui *UI, e tcell.Event) bool { return false } func (s *statusBar) handleEvent(ui *UI, e tcell.Event) bool { return false }
func (s *statusBar) draw(b *buffer) { func (s *statusBar) draw(b *buffer) {
if s.ui == nil { line := fmt.Sprintf("shown: %08d cleared: %08d messages: %08d", s.showCount, s.clearCount, s.msgCount)
return
}
line := fmt.Sprintf("shown: %08d cleared: %08d messages: %08d", s.ui.showCount, s.ui.clearCount, s.ui.msgCount)
b.writeString(line, math.Vec{0, 0}, tcell.StyleDefault) b.writeString(line, math.Vec{0, 0}, tcell.StyleDefault)
} }

@ -18,10 +18,6 @@ type UI struct {
room *wire.Room room *wire.Room
client *wire.Client client *wire.Client
msgCount int
showCount int
clearCount int
statusBar *statusBar statusBar *statusBar
gameView *gameView gameView *gameView
chatView *chatView chatView *chatView
@ -66,9 +62,7 @@ func (ui *UI) Run() {
Log: ui.Child("chat-view"), Log: ui.Child("chat-view"),
history: make([]sim.ChatMessage, 0, 32), history: make([]sim.ChatMessage, 0, 32),
} }
ui.statusBar = &statusBar{ ui.statusBar = &statusBar{}
ui: ui,
}
ui.focussed = ui.gameView ui.focussed = ui.gameView
ui.Info("running ui") ui.Info("running ui")
@ -117,14 +111,14 @@ func (ui *UI) setupTerminal() {
} }
func (ui *UI) clearTerminal() { func (ui *UI) clearTerminal() {
ui.clearCount++ ui.statusBar.clearCount++
ui.screen.Clear() ui.screen.Clear()
ui.screen.Fini() ui.screen.Fini()
} }
func (ui *UI) handleNotifications(c <-chan wire.Response) { func (ui *UI) handleNotifications(c <-chan wire.Response) {
for n := range c { for n := range c {
ui.msgCount++ ui.statusBar.msgCount++
if ui.handleNotification(n.Body) { if ui.handleNotification(n.Body) {
if ui.gameView != nil { if ui.gameView != nil {
ui.render() ui.render()
@ -133,7 +127,7 @@ func (ui *UI) handleNotifications(c <-chan wire.Response) {
} }
ui.Info("notifications channel is closed so we must be done") ui.Info("notifications channel is closed so we must be done")
ui.Info("clearing and finalizing screen from notifications goroutine") ui.Info("clearing and finalizing screen from notifications goroutine")
ui.clearCount++ ui.statusBar.clearCount++
ui.screen.Clear() ui.screen.Clear()
ui.screen.Fini() ui.screen.Fini()
ui.Info("screen finalized") ui.Info("screen finalized")
@ -200,7 +194,7 @@ func (ui *UI) writeString(x, y int, s string, style tcell.Style) {
} }
func (ui *UI) handleUserInput() bool { func (ui *UI) handleUserInput() bool {
ui.clearCount++ ui.statusBar.clearCount++
ui.screen.Clear() ui.screen.Clear()
ui.render() ui.render()
@ -234,10 +228,10 @@ func (ui *UI) handleUserInput() bool {
} }
ui.focussed.handleEvent(ui, e) ui.focussed.handleEvent(ui, e)
ui.clearCount++ ui.statusBar.clearCount++
ui.screen.Clear() ui.screen.Clear()
ui.render() ui.render()
ui.showCount++ ui.statusBar.showCount++
ui.screen.Show() ui.screen.Show()
HANDLED: HANDLED:
} }
@ -265,6 +259,6 @@ func (ui *UI) render() {
b.blit(ui.screen, math.Vec{0, gameViewHeight + 1}) b.blit(ui.screen, math.Vec{0, gameViewHeight + 1})
} }
ui.showCount++ ui.statusBar.showCount++
ui.screen.Show() ui.screen.Show()
} }

Loading…
Cancel
Save