[GH-ISSUE #6] Ability to update the view from a goroutine #4

Closed
opened 2026-03-04 01:01:02 +03:00 by kerem · 5 comments
Owner

Originally created by @dpotapov on GitHub (Jan 10, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/6

Hi,

I'm running some parallel blocking job (like HTTP call) in a goroutine and would like to update the view once it is completed.
Since the main loop is blocked by screen.PollEvent() the screen is not redrawing automatically. Some key/resize event have to trigger it. Another problem with SetFocus() - it blocks while polling events.

Here is example:

app := tview.NewApplication()
a := tview.NewModal().SetText("Waiting 5 seconds...").AddButtons([]string{"Ok"})
b := tview.NewModal().SetText("Done!").AddButtons([]string{"Exit"})

go func() {
	time.Sleep(5 * time.Second) // or http.Get()
	app.SetRoot(b, false).SetFocus(b).Draw()
}()

if err := app.SetRoot(a, false).SetFocus(a).Run(); err != nil {
	panic(err)
}
Originally created by @dpotapov on GitHub (Jan 10, 2018). Original GitHub issue: https://github.com/rivo/tview/issues/6 Hi, I'm running some parallel blocking job (like HTTP call) in a goroutine and would like to update the view once it is completed. Since the main loop is blocked by `screen.PollEvent()` the screen is not redrawing automatically. Some key/resize event have to trigger it. Another problem with `SetFocus()` - it blocks while polling events. Here is example: ```go app := tview.NewApplication() a := tview.NewModal().SetText("Waiting 5 seconds...").AddButtons([]string{"Ok"}) b := tview.NewModal().SetText("Done!").AddButtons([]string{"Exit"}) go func() { time.Sleep(5 * time.Second) // or http.Get() app.SetRoot(b, false).SetFocus(b).Draw() }() if err := app.SetRoot(a, false).SetFocus(a).Run(); err != nil { panic(err) } ```
kerem closed this issue 2026-03-04 01:01:03 +03:00
Author
Owner

@rivo commented on GitHub (Jan 11, 2018):

Thanks for the hint. I just pushed a change which will fix your example. I decided not to lock while polling for events. I don't see a reason why this couldn't be removed. I hope your issues are resolved with this now. If not, let me know. (Examples always help.)

I won't merge this pull request then.

By the way, SetRoot() implicitly calls SetFocus().

<!-- gh-comment-id:356900378 --> @rivo commented on GitHub (Jan 11, 2018): Thanks for the hint. I just pushed a change which will fix your example. I decided not to lock while polling for events. I don't see a reason why this couldn't be removed. I hope your issues are resolved with this now. If not, let me know. (Examples always help.) I won't merge this pull request then. By the way, `SetRoot()` implicitly calls `SetFocus()`.
Author
Owner

@rivo commented on GitHub (Jan 11, 2018):

Sorry, just saw that your change wasn't a pull request. So all good then.

<!-- gh-comment-id:356900738 --> @rivo commented on GitHub (Jan 11, 2018): Sorry, just saw that your change wasn't a pull request. So all good then.
Author
Owner

@dpotapov commented on GitHub (Jan 11, 2018):

Thanks!

<!-- gh-comment-id:356933718 --> @dpotapov commented on GitHub (Jan 11, 2018): Thanks!
Author
Owner

@AllanWang commented on GitHub (Mar 3, 2018):

@rivo sorry to bring this back from the dead, but some of your examples call SetRoot() as well as SetFocus(). See flexbox. Maybe you'll want to update those examples?

<!-- gh-comment-id:370104759 --> @AllanWang commented on GitHub (Mar 3, 2018): @rivo sorry to bring this back from the dead, but some of your examples call `SetRoot()` as well as `SetFocus()`. See [flexbox](https://github.com/rivo/tview/blob/master/demos/flex/main.go). Maybe you'll want to update those examples?
Author
Owner

@rivo commented on GitHub (Mar 5, 2018):

Right. I missed that. Should be fixed with the latest commit (c2f07f9548). Thanks.

<!-- gh-comment-id:370460880 --> @rivo commented on GitHub (Mar 5, 2018): Right. I missed that. Should be fixed with the latest commit (c2f07f95484c7bead2bac61de12030815e2aab58). Thanks.
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#4
No description provided.