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

Generalize Terminal Backend cleanup #1042

Open
EdJoPaTo opened this issue Apr 16, 2024 · 1 comment
Open

Generalize Terminal Backend cleanup #1042

EdJoPaTo opened this issue Apr 16, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@EdJoPaTo
Copy link
Member

Problem

All the examples and real world applications contain some kind of 'return back to the normal terminal' code.
This should be generalized as the normal state is known: show cursor, leave raw mode and alternate screen, …

Solution

This is specific to the backend and could be made available for each Backend.
Some backends take their inner writer which could also be returned here.
So I think this shouldn't be a trait method and rather Backend specific?

It might also be useful to use this without the Backend in order to be used from a panic handler.

Pseudocode:

main_loop();
CrosstermBackend::restore()

There is also a Drop implementation for Terminal which partially tries this but can not do this as well as each Backend implementation should be.

Not sure if a Drop implementation would be helpful rather than an explicit method to be called.
Currently, all the examples call explicit methods, so I don't see a big drawback on doing that just simpler with a Backend specific method provided by ratatui.

Regarding the setup: I don't think this can be generalized as easy. Some examples don't use the alternate screen for example. There could be a generic method for the hide cursor, alternate screen case but not everyone would use that then depending on their use-case.

@joshka
Copy link
Member

joshka commented Apr 21, 2024

There's a previous PR that is closed without merge but has many comments that are relevant - #280
and a corresponding issue: #261
Both are semi-related to this

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

No branches or pull requests

2 participants