get message window updating and scrolling

trunk
vilmibm 2022-07-09 02:29:08 -05:00
parent 10a5794cd9
commit 9bdbc9d658
2 changed files with 9 additions and 12 deletions

View File

@ -23,7 +23,7 @@ var (
) )
func messages(cs *ClientState) error { func messages(cs *ClientState) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
stream, err := cs.Client.Messages(ctx, cs.SessionInfo) stream, err := cs.Client.Messages(ctx, cs.SessionInfo)
if err != nil { if err != nil {
@ -60,12 +60,11 @@ func (cs *ClientState) AddMessage(msg *proto.ClientMessage) {
cs.messages = cs.messages[1 : len(cs.messages)-1] cs.messages = cs.messages[1 : len(cs.messages)-1]
} }
// TODO look into using the SetChangedFunc thing.
cs.App.QueueUpdateDraw(func() { cs.App.QueueUpdateDraw(func() {
cs.messagesView.SetText("") // 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())
for _, msg := range cs.messages { cs.messagesView.ScrollToEnd()
fmt.Fprintf(cs.messagesView, "%#v\n", msg)
}
}) })
} }
@ -116,8 +115,6 @@ func _main() error {
log.Fatalf("%v.Ping -> %v", cs.Client, err) log.Fatalf("%v.Ping -> %v", cs.Client, err)
} }
//stream, err := messageStream(client, sessionInfo)
log.Printf("%#v", pong) log.Printf("%#v", pong)
pages := tview.NewPages() pages := tview.NewPages()
@ -144,7 +141,7 @@ func _main() error {
pages.AddPage("main", mainPage, true, false) pages.AddPage("main", mainPage, true, false)
msgView := tview.NewTextView() msgView := tview.NewTextView().SetScrollable(true).SetWrap(true).SetWordWrap(true)
cs.messagesView = msgView cs.messagesView = msgView
gamePage := tview.NewGrid(). gamePage := tview.NewGrid().

View File

@ -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 { 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{} msg := &proto.ClientMessage{}
speaker := "snoozy" speaker := "snoozy"
msg.Speaker = &speaker msg.Speaker = &speaker
msg.Type = proto.ClientMessage_WHISPER 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) stream.Send(msg)
time.Sleep(2 * time.Second) time.Sleep(500 * time.Millisecond)
} }
return nil return nil
} }