Skip to content

Issues with Viewport SetContent #373

@jamesthesken

Description

@jamesthesken

Hey Charm team, thank you for this library as it's been very inspiring and fun to work with!

I am working on an IRC client, and having some trouble updating the Viewport component:
https://github.com/jamesthesken/go-irc/tree/tui_v1

The Issue

In go-irc/tui/tui.go there is a function called StartTea(), which starts a goroutine that listens for incoming messages from an IRC server.

This function, Read() calls model.Update(RcvMessage{content: msgRcv}), where RcvMessage is defined as:

type RcvMessage struct {
	content string
}

After this message is received it is processed by a switch statement in Update():

case RcvMessage:
		// this does not work:
		m.messages = append(m.messages, m.senderStyle.Render("Server: ")+string(msg.content))
		m.viewport.SetContent(strings.Join(m.messages, "\n"))
		fmt.Print(msg.content) // but this does ??
		m.viewport.GotoBottom()

I can't seem to figure it out, but I can print the message contents to the screen, yet setting content in the Viewport does not work as expected. Even with a dummy string (I.e., m.viewport.SetContent("received")

Could there be a race condition between my message retrieval goroutine and updating the viewport?

Thank you in advance for any help and insight!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions