diff --git a/internal/app/buffer.go b/internal/app/buffer.go index 38bf1ed..0fa2441 100644 --- a/internal/app/buffer.go +++ b/internal/app/buffer.go @@ -55,3 +55,11 @@ func (b *buffer) blit(s tcell.Screen, offset math.Vec) { } } } + +func (b *buffer) fill(style tcell.Style) { + for x := 0; x < b.width; x++ { + for y := 0; y < b.height; y++ { + b.set(x, y, tile{r: ' ', style: style}) + } + } +} diff --git a/internal/app/status_bar.go b/internal/app/status_bar.go new file mode 100644 index 0000000..f2db4c1 --- /dev/null +++ b/internal/app/status_bar.go @@ -0,0 +1,25 @@ +package app + +import ( + "fmt" + + "github.com/gdamore/tcell/v2" + "github.com/jordanorelli/astro-domu/internal/math" +) + +type statusBar struct { + inFocus bool + ui *UI +} + +func (s *statusBar) handleEvent(ui *UI, e tcell.Event) bool { return false } + +func (s *statusBar) draw(b *buffer) { + if s.ui == nil { + return + } + line := fmt.Sprintf("shown: %08d cleared: %08d", s.ui.showCount, s.ui.clearCount) + b.writeString(line, math.Vec{0, 0}, tcell.StyleDefault) +} + +func (s *statusBar) setFocus(enabled bool) { s.inFocus = enabled } diff --git a/internal/app/ui.go b/internal/app/ui.go index ccb80fe..339e41c 100644 --- a/internal/app/ui.go +++ b/internal/app/ui.go @@ -17,10 +17,13 @@ type UI struct { screen tcell.Screen room *wire.Room client *wire.Client + showCount int + clearCount int - gameView *gameView - chatView *chatView - focussed view + statusBar *statusBar + gameView *gameView + chatView *chatView + focussed view } func (ui *UI) Run() { @@ -61,6 +64,9 @@ func (ui *UI) Run() { Log: ui.Child("chat-view"), history: make([]sim.ChatMessage, 0, 32), } + ui.statusBar = &statusBar{ + ui: ui, + } ui.focussed = ui.gameView ui.Info("running ui") @@ -109,6 +115,7 @@ func (ui *UI) setupTerminal() { } func (ui *UI) clearTerminal() { + ui.clearCount++ ui.screen.Clear() ui.screen.Fini() } @@ -123,6 +130,7 @@ func (ui *UI) handleNotifications(c <-chan wire.Response) { } ui.Info("notifications channel is closed so we must be done") ui.Info("clearing and finalizing screen from notifications goroutine") + ui.clearCount++ ui.screen.Clear() ui.screen.Fini() ui.Info("screen finalized") @@ -173,6 +181,7 @@ func (ui *UI) writeString(x, y int, s string, style tcell.Style) { } func (ui *UI) handleUserInput() bool { + ui.clearCount++ ui.screen.Clear() ui.render() @@ -206,8 +215,10 @@ func (ui *UI) handleUserInput() bool { } ui.focussed.handleEvent(ui, e) + ui.clearCount++ ui.screen.Clear() ui.render() + ui.showCount++ ui.screen.Show() HANDLED: } @@ -217,16 +228,24 @@ func (ui *UI) render() { width, height := ui.screen.Size() { - b := newBuffer(width/2, height/2) - ui.gameView.draw(b) + b := newBuffer(width, 1) + ui.statusBar.draw(b) b.blit(ui.screen, math.Vec{0, 0}) } + gameViewHeight := math.Max((height-1)/2, 8) + { + b := newBuffer(width/2, gameViewHeight) + ui.gameView.draw(b) + b.blit(ui.screen, math.Vec{0, 1}) + } + { - b := newBuffer(width, height/2) + b := newBuffer(width, height-gameViewHeight-1) ui.chatView.draw(b) - b.blit(ui.screen, math.Vec{0, height / 2}) + b.blit(ui.screen, math.Vec{0, gameViewHeight + 1}) } + ui.showCount++ ui.screen.Show() }