[GH-ISSUE #1078] Can I switch pages multiple times within SelectedFunc? #782

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

Originally created by @ryutaro-asada on GitHub (Mar 22, 2025).
Original GitHub issue: https://github.com/rivo/tview/issues/1078

Hello.
i have a question.

I want to show a loading modal when I select a table row, so I wrote the following code:

	Table.SetSelectedFunc(func(row, column int) {
		cell := Table.GetCell(row, 0)

		g.pages.ShowPage("NowLoadingModalPage")

                // take a while
		g.setLogStreamToGui(cell.Text)

		g.pages.HidePage("NowLoadingModalPage")
	})

However, it seems like the modal is not shown.
I think the reason is that the modal is shown and hidden at the same time.
How can I show the modal before the setLogStreamToGui function is called?

Originally created by @ryutaro-asada on GitHub (Mar 22, 2025). Original GitHub issue: https://github.com/rivo/tview/issues/1078 Hello. i have a question. I want to show a loading modal when I select a table row, so I wrote the following code: ```go Table.SetSelectedFunc(func(row, column int) { cell := Table.GetCell(row, 0) g.pages.ShowPage("NowLoadingModalPage") // take a while g.setLogStreamToGui(cell.Text) g.pages.HidePage("NowLoadingModalPage") }) ``` However, it seems like the modal is not shown. I think the reason is that the modal is shown and hidden at the same time. How can I show the modal before the setLogStreamToGui function is called?
kerem closed this issue 2026-03-04 01:07:42 +03:00
Author
Owner

@rivo commented on GitHub (Mar 27, 2025):

Redrawing happens after the selectedFunc is done. So you're basically showing a page, then hiding it again before tview redraws the screen. That's why you don't see anything.

I don't know what your setLogStreamToGui function does but if it takes a while and you don't mind your application being unresponsive during its execution, you can use Application.QueueUpdateDraw to call setLogStreamToGui and HidePage.

If your application needs to be responsive while setLogStreamToGui executes, that's a bit trickier. You might want to read the following Wiki page to get some clues: https://github.com/rivo/tview/wiki/Concurrency

<!-- gh-comment-id:2759703641 --> @rivo commented on GitHub (Mar 27, 2025): Redrawing happens after the `selectedFunc` is done. So you're basically showing a page, then hiding it again before `tview` redraws the screen. That's why you don't see anything. I don't know what your `setLogStreamToGui` function does but if it takes a while and you don't mind your application being unresponsive during its execution, you can use [`Application.QueueUpdateDraw`](Application.QueueUpdateDrawhttps://pkg.go.dev/github.com/rivo/tview#Application.QueueUpdateDraw) to call `setLogStreamToGui` and `HidePage`. If your application needs to be responsive while `setLogStreamToGui` executes, that's a bit trickier. You might want to read the following Wiki page to get some clues: https://github.com/rivo/tview/wiki/Concurrency
Author
Owner

@ryutaro-asada commented on GitHub (Mar 28, 2025):

Thank you .

<!-- gh-comment-id:2760557464 --> @ryutaro-asada commented on GitHub (Mar 28, 2025): Thank you .
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#782
No description provided.