-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to change instantiation properties during widget redrawing? #242
Comments
I think there may be a simple solution. If you look at the signature of these two functions: The constructor: termdash/widgets/sparkline/sparkline.go Lines 52 to 53 in 660ef91
Method that updates the widget's value: termdash/widgets/sparkline/sparkline.go Lines 145 to 159 in 660ef91
You'll notice that they both take optional variadic argument of type Option. You can try passing in the Feel free to let me know if you have any further questions or if this doesn't work. |
Great! As always, you nailed it! What about Button? What is the "magic" method for it? Looking at the code I couldn't find. What do you thing about creating a Button.Update(opts ... Option) method? |
True, not all widgets provide this functionality consistently. Adding an The other option would be to do something similar to what you did before (create a new button and replace the old one). There actually is an infrastructure supported way of doing that using the Dynamic Layout feature. Let me know if you are interested in sending a PR that will add the Update method or if you have any further questions about the dynamic layout. |
Great... I tried to create an "Update()" method but the results weren't good, so I would have to to deeper. If you have some time, please take a look at https://github.com/flaviostutz/termdash/blob/%23242-add-opts/widgets/button/button.go on method "ApplyOpts(..)" and pls tell me what's is wrong. In my tests the layout got messed up. My app has a severe memory leak and I think it is due to the updating the pointer variable contents somehow (have to go deeper on this). I didn't know the dynamic layout feature. I will surely try it later. Thanks again for the great support you provide! |
Looking at the func (b *Button) ApplyOpts(text string, opts ...Option) error {
b.mu.Lock() // Acquires mutex
defer b.mu.Unlock() // Releases mutex
b.text = text
opt := newOptions(b.text)
for _, o := range opts {
o.set(opt)
}
if err := opt.validate(); err != nil {
return err
}
b.opts = opt
return nil
} Without knowing more details about why the results weren't good, this may be the best guess I can provide. Please let me know if this helped. If not, try to provide more details about the behavior you are observing. Updating the pointer shouldn't cause a long-term memory leak. Sure there will be larger memory usage for a while until Go's garbage collector decides to release memory used by the old instances, but that should even out. If you see continuous increase of memory usage, I would recommend trying to profile the memory usage. You can upload the resulting profile diagram here and we can look at it together. Feel free to let me know if you would like to hear more details about race condition, mutexes or profiling, happy to answer questions if I do know the answers. |
I am creating a monitoring dashboard in which I want to change the color of slackline, for example, depending on other things happening on the system (not the value itself, which is not possible too).
For doing this, I made something very questionable, but it worked:
For the real code, see https://github.com/flaviostutz/perfstat/blob/master/cli/home.go
Is there a better way to do this kind of property modifications or it could be better exposed on termdash API?
The text was updated successfully, but these errors were encountered: