ratatui-org / ratatui

Rust library that's all about cooking up terminal user interfaces (TUIs) 👨‍🍳🐀

Home Page:https://ratatui.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generalize Terminal Backend cleanup

EdJoPaTo opened this issue · comments

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.

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

Related PR #1180