mirror of
https://github.com/rivo/tview.git
synced 2026-04-27 05:45:49 +03:00
[GH-ISSUE #899] Question about textview refreshing content in real time #656
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#656
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @7yyo on GitHub (Oct 12, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/899
After adding setDoneFunc to an item, execute a piece of code logic. This process will print some logs. These logs will be transferred to another textview for display. However, the program can only display all logs after setDoneFunc ends and will not output them in real time. This Why? I can provide pseudocode if necessary. The code is similar to the demo of textview
@rivo commented on GitHub (Oct 12, 2023):
Yes, please provide some brief code that can be run to reproduce this.
@7yyo commented on GitHub (Oct 13, 2023):
@rivo Thanks for the response. The following code can be run directly. There is a treeView and a textView. When setDoneFunc is executed, some strings will be output to textView for display, but they can only be displayed after setDoneFunc is executed. Strings cannot be printed out in textView in real time.
@rivo commented on GitHub (Oct 20, 2023):
@digitallyserviced is generally right in that your
SetDoneFuncis part of the main goroutine. So if you're blocking that function (with your sleep calls, in this example), you're blocking everything basically. If you want to stream text to yourTextView, you need to do it from a separate goroutine. If you know all text in advance, however, just useSetText()without thetime.Sleepcalls (no goroutine needed in that case).A few additional notes:
app.Draw()from yourSetChangedFunc. No need to callQueueUpdateDraw()like @digitallyserviced suggested (see the documentation for details).SetDoneFunccan be used in theory but it's usually reserved to be used internally for forms. (Yes, it shouldn't have been exposed in the first place.) MaybeSetSelectedFuncorSetInputCapturewith your own bindings is better..SetRows(0, 0).SetColumns(0, 0)calls are not needed: "A value of 0 is assumed for any undefined column.".@7yyo commented on GitHub (Oct 23, 2023):
@rivo @digitallyserviced thanks!
To summarize, this code solves the problem I raised
However, I added grid.RemoveItem(treeView) and tried to delete the treeview before the goroutine ended, but it failed. Why is this?
@rivo commented on GitHub (Oct 23, 2023):
You can't make other, especially structural changes to your widgets in a separate goroutine. For example, if the application is currently re-drawing the screen while you change objects that need to be drawn, you will run in to race issues. (The
io.Readerinterface ofTextViewis an exception here.)Please read the following article about concurrency in
tview:https://github.com/rivo/tview/wiki/Concurrency
For your specific program, you will have to wrap
grid.RemoveItem(treeView)in aapp.QueueUpdateDraw().@7yyo commented on GitHub (Oct 23, 2023):
@rivo I modified it like this but it still doesn't work. What's the problem?
@rivo commented on GitHub (Oct 23, 2023):
You don't need the second goroutine.
Can you be a bit more specific? What exactly does not work?
@7yyo commented on GitHub (Oct 24, 2023):
@rivo The code is like this, but textview cannot be automatically hidden
@rivo commented on GitHub (Oct 24, 2023):
It did disappear but the screen was not cleared before redrawing everything so you could still see the remainders of the last
app.Drawcycle. With the latest commit, the application will always clear the screen before drawing all elements. Try your example with the newest version oftview.@7yyo commented on GitHub (Oct 24, 2023):
@rivo After updating to the latest version, it really works. This project is so cool and the updates are timely. Thanks for the help, I will always support it!
@rivo commented on GitHub (Oct 24, 2023):
@7yyo Thank you for the nice words. I try to fix bugs quickly but there may be times when I'm too busy to respond as quickly as I have in this case. Any way, I'm glad it works now.