Skip to content
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

remove the <'a> requirement on TextArea #46

Closed
pm100 opened this issue Nov 7, 2023 · 8 comments
Closed

remove the <'a> requirement on TextArea #46

pm100 opened this issue Nov 7, 2023 · 8 comments

Comments

@pm100
Copy link
Contributor

pm100 commented Nov 7, 2023

Dropping TTA into an existing project can be very disruptive since it requires lifetime annotation. This can ripple up through an app. This makes it a barrier to adoption by other projects (speaking from experience here)

The solution would be to have a private Block equivalent that owns the title string (s) rather than using references.

@pm100 pm100 mentioned this issue Nov 8, 2023
@rhysd
Copy link
Owner

rhysd commented Nov 8, 2023

The lifetime parameter is used for ratatui's Block instance which is set to inner Pragraph on rendering. It cannot be removed.

@pm100
Copy link
Contributor Author

pm100 commented Nov 8, 2023

I know, hence the different block in my pr

@rhysd
Copy link
Owner

rhysd commented Nov 9, 2023

I saw your PR changes a bit. Do you mean adding new API which is very similar to Block only for removing the lifetime parameter? I don't think it is a good tradeoff. We should use ratatui's API as much as possible to make our API as minimal as possible. If we add new widget, users need to learn about it. I feel the cost is much bigger than just handling small one lifetime parameter.

If you want to hide the parameter and you're not benefit from it, you can do:

type TextArea = TextArea<'static>;

@pm100
Copy link
Contributor Author

pm100 commented Nov 9, 2023

I tried multiple things to avoid propagating the 'a over several weeks , and yet I never tried that one :-). I know it comes with some restrictions, I need to check if it will work in gitui.

@pm100
Copy link
Contributor Author

pm100 commented Nov 9, 2023

Ty, that worked beautifully. I should have asked you in the first place

@pm100 pm100 closed this as completed Nov 9, 2023
@rhysd
Copy link
Owner

rhysd commented Nov 9, 2023

Great. Thanks for your confirmation.

@joshka
Copy link
Contributor

joshka commented Nov 9, 2023

Ha - I almost mentioned the same solution in the Ratatui side of this :D

@holly-hacker
Copy link

Could this be documented somewhere? I just spent 15 minutes adding and removing lifetimes everywhere and was about to open a duplicate of this issue. Using a 'static lifetime is a fine workaround but it's something you need to be aware off first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants