get message window updating and scrolling
parent
10a5794cd9
commit
9bdbc9d658
|
@ -23,7 +23,7 @@ var (
|
|||
)
|
||||
|
||||
func messages(cs *ClientState) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
stream, err := cs.Client.Messages(ctx, cs.SessionInfo)
|
||||
if err != nil {
|
||||
|
@ -60,12 +60,11 @@ func (cs *ClientState) AddMessage(msg *proto.ClientMessage) {
|
|||
cs.messages = cs.messages[1 : len(cs.messages)-1]
|
||||
}
|
||||
|
||||
// TODO look into using the SetChangedFunc thing.
|
||||
cs.App.QueueUpdateDraw(func() {
|
||||
cs.messagesView.SetText("")
|
||||
|
||||
for _, msg := range cs.messages {
|
||||
fmt.Fprintf(cs.messagesView, "%#v\n", msg)
|
||||
}
|
||||
// TODO trim content of messagesView /or/ see if tview has a buffer size that does it for me. use cs.messages to re-constitute.
|
||||
fmt.Fprintf(cs.messagesView, "%s: %s\n", msg.GetSpeaker(), msg.GetText())
|
||||
cs.messagesView.ScrollToEnd()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -116,8 +115,6 @@ func _main() error {
|
|||
log.Fatalf("%v.Ping -> %v", cs.Client, err)
|
||||
}
|
||||
|
||||
//stream, err := messageStream(client, sessionInfo)
|
||||
|
||||
log.Printf("%#v", pong)
|
||||
|
||||
pages := tview.NewPages()
|
||||
|
@ -144,7 +141,7 @@ func _main() error {
|
|||
|
||||
pages.AddPage("main", mainPage, true, false)
|
||||
|
||||
msgView := tview.NewTextView()
|
||||
msgView := tview.NewTextView().SetScrollable(true).SetWrap(true).SetWordWrap(true)
|
||||
cs.messagesView = msgView
|
||||
|
||||
gamePage := tview.NewGrid().
|
||||
|
|
|
@ -70,14 +70,14 @@ func (s *gameWorldServer) Ping(ctx context.Context, _ *proto.SessionInfo) (*prot
|
|||
}
|
||||
|
||||
func (s *gameWorldServer) Messages(si *proto.SessionInfo, stream proto.GameWorld_MessagesServer) error {
|
||||
for x := 0; x < 20; x++ {
|
||||
for x := 0; x < 100; x++ {
|
||||
msg := &proto.ClientMessage{}
|
||||
speaker := "snoozy"
|
||||
msg.Speaker = &speaker
|
||||
msg.Type = proto.ClientMessage_WHISPER
|
||||
msg.Text = fmt.Sprintf("have message %d", x)
|
||||
msg.Text = fmt.Sprintf("hi this is message %d. by the way i am a horse. neigh neigh neigh neigh neigh neigh neigh neigh neigh neigh neigh neigh", x)
|
||||
stream.Send(msg)
|
||||
time.Sleep(2 * time.Second)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue