diff --git a/ui_mode.go b/internal/ui/mode.go similarity index 91% rename from ui_mode.go rename to internal/ui/mode.go index 0b2a2a2..4f8d3b5 100644 --- a/ui_mode.go +++ b/internal/ui/mode.go @@ -1,13 +1,13 @@ -package main +package ui import ( "github.com/gdamore/tcell/v2" "github.com/jordanorelli/astro-domu/internal/wire" ) -type uiMode interface { - handleEvent(*ui, tcell.Event) bool - draw(*ui) +type Mode interface { + handleEvent(*UI, tcell.Event) bool + draw(*UI) } type boxWalker struct { @@ -16,7 +16,7 @@ type boxWalker struct { position point } -func (m *boxWalker) handleEvent(ui *ui, e tcell.Event) bool { +func (m *boxWalker) handleEvent(ui *UI, e tcell.Event) bool { switch v := e.(type) { case *tcell.EventKey: key := v.Key() @@ -47,7 +47,7 @@ func (m *boxWalker) move(dx, dy int) { m.position.y = clamp(m.position.y+dy, 0, m.height-1) } -func (m *boxWalker) draw(ui *ui) { +func (m *boxWalker) draw(ui *UI) { offset := point{1, 1} // fill in background dots first diff --git a/point.go b/internal/ui/point.go similarity index 91% rename from point.go rename to internal/ui/point.go index bcb22c1..cb44cad 100644 --- a/point.go +++ b/internal/ui/point.go @@ -1,4 +1,4 @@ -package main +package ui type point struct{ x, y int } diff --git a/ui.go b/internal/ui/ui.go similarity index 91% rename from ui.go rename to internal/ui/ui.go index fa2dc6f..891ac5a 100644 --- a/ui.go +++ b/internal/ui/ui.go @@ -1,4 +1,4 @@ -package main +package ui import ( "context" @@ -10,15 +10,14 @@ import ( "github.com/jordanorelli/blammo" ) -// ui represents our terminal-based user interface -type ui struct { +type UI struct { *blammo.Log screen tcell.Screen - mode uiMode + mode Mode client *wire.Client } -func (ui *ui) run() { +func (ui *UI) Run() { ui.client = &wire.Client{ Log: ui.Child("client"), Host: "127.0.0.1", @@ -75,7 +74,7 @@ func (ui *ui) run() { // writeString writes a string in the given style from left to right beginning // at the location (x, y). Writing of the screen just fails silently so don't // do that. -func (ui *ui) writeString(x, y int, s string, style tcell.Style) { +func (ui *UI) writeString(x, y int, s string, style tcell.Style) { width, height := ui.screen.Size() if y > height { return @@ -89,7 +88,7 @@ func (ui *ui) writeString(x, y int, s string, style tcell.Style) { } } -func (ui *ui) menu() { +func (ui *UI) menu() { ui.screen.Clear() _, height := ui.screen.Size() ui.writeString(0, height-1, "fart", tcell.StyleDefault) diff --git a/main.go b/main.go index 1335419..dad41a0 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "github.com/jordanorelli/astro-domu/internal/exit" "github.com/jordanorelli/astro-domu/internal/server" + "github.com/jordanorelli/astro-domu/internal/ui" "github.com/jordanorelli/blammo" ) @@ -61,8 +62,8 @@ func runClient() { log.Info("total play time: %v", finished.Sub(start)) }() - ui := ui{ + ui := ui.UI{ Log: log.Child("ui"), } - ui.run() + ui.Run() }