master
Jordan Orelli 4 years ago
parent 53a7e11936
commit 04346a65b1

@ -11,7 +11,6 @@ import (
type chatView struct { type chatView struct {
composing string composing string
inFocus bool inFocus bool
history []sim.ChatMessage
} }
func (c *chatView) handleEvent(e tcell.Event) change { func (c *chatView) handleEvent(e tcell.Event) change {
@ -51,8 +50,8 @@ func (c *chatView) draw(img canvas, st *state) {
bounds := img.bounds() bounds := img.bounds()
fill(img, tcell.StyleDefault.Background(tcell.NewRGBColor(32, 32, 32))) fill(img, tcell.StyleDefault.Background(tcell.NewRGBColor(32, 32, 32)))
chatHeight := bounds.Height - 1 chatHeight := bounds.Height - 1
for i := 0; i < math.Min(chatHeight, len(c.history)); i++ { for i := 0; i < math.Min(chatHeight, len(st.history)); i++ {
msg := c.history[len(c.history)-1-i] msg := st.history[len(st.history)-1-i]
s := fmt.Sprintf("%12s: %s", msg.From, msg.Text) s := fmt.Sprintf("%12s: %s", msg.From, msg.Text)
writeString(img, s, math.Vec{0, bounds.Height - 2 - i}, tcell.StyleDefault) writeString(img, s, math.Vec{0, bounds.Height - 2 - i}, tcell.StyleDefault)
} }

@ -1,8 +1,12 @@
package app package app
import "github.com/jordanorelli/astro-domu/internal/wire" import (
"github.com/jordanorelli/astro-domu/internal/sim"
"github.com/jordanorelli/astro-domu/internal/wire"
)
type state struct { type state struct {
playerName string playerName string
room *wire.Room room *wire.Room
history []sim.ChatMessage
} }

@ -128,7 +128,7 @@ func (ui *UI) handleNotification(v wire.Value) bool {
return true return true
case *sim.ChatMessage: case *sim.ChatMessage:
// ui.chatView.history = append(ui.chatView.history, *n) ui.state.history = append(ui.state.history, *n)
return true return true
default: default:

Loading…
Cancel
Save