mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #197] Timer Example #155
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#155
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 @lnxbil on GitHub (Nov 27, 2018).
Original GitHub issue: https://github.com/rivo/tview/issues/197
Hi Oliver,
I'm currently researching and trying different tui libraries for GO and wanted a MWE for a timer based implemention with
tviewand want to ask if you'd be willing to include it yourdemosrepository.I based it on your modal example and already created everything for pull request but wanted to ask first as suggested by your
CONTRIBUTING.md:Code is
@rivo commented on GitHub (Dec 3, 2018):
Hi Andreas,
Thanks for contributing. Is there any reason you want this specific example in the package? I'm trying to keep the demos as minimal as possible, to give people something simple to start with.
However, I'm happy to include it in the Wiki, if you want. Before doing that, I'd make the following modifications, though:
view.SetText()needs to be wrapped in anapp.QueueUpdateDraw()call to avoid race conditions. See the Wiki for details.refreshIntervalshould probably be a constant.varstatements with brackets()(just a cosmetic change).Let me know what you think about that.
@lnxbil commented on GitHub (Dec 10, 2018):
Sorry, for answering so late.
Yes, an example in the Wiki would be great, too. I didn't realize there is something in the wiki at all. Often I just try the examples in the GIT and do not explicitly look for other examples in the wiki - at least I normally do not expect to find other/additional examples. My bad. Now I also know where the postgres examples comes from and can play around with it.
Here is the updated code that can go in the wiki:
@rivo commented on GitHub (Dec 14, 2018):
I added your code to the Wiki with some minor changes: https://github.com/rivo/tview/wiki/Timer
The package itself only contains very simple examples to get people started. For more elaborate examples, we have the Wiki. The Wiki also contains longer discussions of various topics. For example, the page about Concurrency where I've also added a link to your Timer example.
@ardnew commented on GitHub (Dec 14, 2018):
I use a similar pattern as this, but with Go's standard
time.Tickerchannel combined withtview.Box's providedSetDrawFunc()callback, which allows writing to arbitrary locations on screen. It's more primitive, but also a little more versatile and idiomatic in my opinion:@ardnew commented on GitHub (Dec 14, 2018):
Also, note the empty anonymous function passed into
QueueUpdateDraw()in my example. This is simply to enqueue aDraw()onto the event loop (without using a sillyQueueUpdate(func(){ app.Draw() })) . If you pass a nil function in, it will segfault with a nil pointer dereference. I haven't looked at the tview code handling this, but I wonder if there is any way to safely have tview just enqueue theDraw()in this case and not attempt to exec the callback?@rivo commented on GitHub (Dec 14, 2018):
Actually, if you call
Application.Draw(), it is automatically queued. No need to useQueueUpdate()orQueueUpdateDraw()here. I clarified this in the package description:Do you want me to add this to the Wiki, too? I wouldn't replace the other example because both programs illustrate different things:
app.Draw(), then update your primitive in response to it.I could post both in the Wiki along with some comments highlighting the differences.
@ardnew commented on GitHub (Dec 14, 2018):
Yeah that would be great if you added it. And thanks for the feedback, honestly wasn't sure if I was misusing
tviewthis way@rivo commented on GitHub (Dec 15, 2018):
I added your code, too.