mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 13:25:51 +03:00
[GH-ISSUE #136] OnRun()? #107
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#107
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 @undeadindustries on GitHub (Jul 2, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/136
Is there a way to run a func when Run is called?
For example, my app needs to load many files into memory. I want it to start doing that before loading anything else, while displaying a spinner modal... I'd rather not have to have the user press or click anything for it to load these files.
I realize I could just load the files before .Run() but the user would just be waiting before any Box popped up...
Thanks!
@rivo commented on GitHub (Jul 3, 2018):
I'm not completely sure I understand your request. Are you talking about the
Application'sRun()method? That method is typically only called once at the very beginning of your program. Nothing fromtviewis displayed before you call this function. You can run your function immediately beforeRun()or you can start it in parallel in a goroutine.If you want to show some state during the loading of your files without allowing the user to interact with the application, you'll want to use
Pages. Create a page with your state (e.g. ATextViewwith the text "Loading (80%)..."). When loading has finished, you switch to a page that contains the elements of your application.If you want your application's elements to be visible already, you can also place a modal on top of them with the loading progress information. Here is some documentation on how to work with modals.
Does this answer your question?
@undeadindustries commented on GitHub (Jul 3, 2018):
Thank you for your reply.
Let me rephrase the question.
I need these files to open without the user having to press a button. I also want to load a spinner (page, modal, whatever) ...
So I was wondering how I could run a function when Focus() is run on an element. So the page would get focus and start loading these files.
Thanks!
@rivo commented on GitHub (Jul 4, 2018):
I'm still not sure why you would need to hook into
Focus(). I wrote up a quick example of how I understand your request and how I'd solve it:Does this do what you need?
@undeadindustries commented on GitHub (Jul 4, 2018):
Thanks. That looks like it could work. Thanks!
@smazurov commented on GitHub (Jul 13, 2018):
@rivo I just wanted to say thanks! Im jumping back into go to write a console app, and your project, responsiveness and code cleanliness is hugely appreciated. Can't thank you enough.
@rivo commented on GitHub (Jul 14, 2018):
Thank you! I really appreciate it.
@mjgarton commented on GitHub (Jul 20, 2018):
The example here is racy. If you remove the sleep and try it with the race detector enabled, it fires fairly reliably.
Here is one example.
@rivo commented on GitHub (Jul 27, 2018):
Thanks @mjgarton. I thought I had this one covered but I was wrong.
Draw()is now thread-safe.I found another race condition but it's part of
tcell. I should probably submit an issue at some point.