[GH-ISSUE #352] Unable to update primitives #262

Closed
opened 2026-03-04 01:03:26 +03:00 by kerem · 2 comments
Owner

Originally created by @zmnpl on GitHub (Oct 11, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/352

Hi, maybe it's jut too late and honestly I'm feeling stupid to ask... But I am unable to update primitves once the app is run. Take the minimal example from "Hello World":

package main

import (
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!")
	if err := app.SetRoot(box, true).Run(); err != nil {
		panic(err)
	}
	// time.Sleep(time.Second)
	// fmt.Println(5*time.Second)
	box.SetTitle("foo")
	app.Draw()
}

The box title simply doesn't change. It seems that this part of the code is not even reached until I terminate the application.
I added the commented lines and those only seem to be executed after I Ctrl+C'd the app.

Please enlighten me. I know I'm missing something obvious... what am I doing wrong =)

Originally created by @zmnpl on GitHub (Oct 11, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/352 Hi, maybe it's jut too late and honestly I'm feeling stupid to ask... But I am unable to update primitves once the app is run. Take the minimal example from "Hello World": ``` package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!") if err := app.SetRoot(box, true).Run(); err != nil { panic(err) } // time.Sleep(time.Second) // fmt.Println(5*time.Second) box.SetTitle("foo") app.Draw() } ``` The box title simply doesn't change. It seems that this part of the code is not even reached until I terminate the application. I added the commented lines and those only seem to be executed after I Ctrl+C'd the app. Please enlighten me. I know I'm missing something obvious... what am I doing wrong =)
kerem closed this issue 2026-03-04 01:03:27 +03:00
Author
Owner

@Bios-Marcel commented on GitHub (Oct 11, 2019):

The call to Run is blocking, therefore the following code only gets executed if you kill the application, which is what happens when hitting Ctrl-C. If you wanna execute any further logic, trigger it either by user interaction or start a new goroutine and use QueueUpdateDraw like this:

go func() {
    time.Sleep(5*time.Second)
    app.QueueUpdateDraw(func() {
        box.SetTitle("New")
    })
}()
app.Run()
<!-- gh-comment-id:541202622 --> @Bios-Marcel commented on GitHub (Oct 11, 2019): The call to `Run` is blocking, therefore the following code only gets executed if you kill the application, which is what happens when hitting Ctrl-C. If you wanna execute any further logic, trigger it either by user interaction or start a new goroutine and use `QueueUpdateDraw` like this: ```go go func() { time.Sleep(5*time.Second) app.QueueUpdateDraw(func() { box.SetTitle("New") }) }() app.Run() ```
Author
Owner

@zmnpl commented on GitHub (Oct 12, 2019):

Thats spot on. Thank you and have a good day kind sir!

<!-- gh-comment-id:541286675 --> @zmnpl commented on GitHub (Oct 12, 2019): Thats spot on. Thank you and have a good day kind sir!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#262
No description provided.