Skip to content

Use ratatui::run() for managing terminal lifecycle #142

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

Merged
merged 6 commits into from
Jul 15, 2025

Conversation

nebkor
Copy link
Contributor

@nebkor nebkor commented Jul 15, 2025

This removes the custom tui module for setting up the terminal and panic handlers, and instead uses the new run() function from Ratatui 0.30. Something to note is that I had to change the main func to be non-async, since the run function takes a sync closure, so I used the Tokio runtime's block_on() method inside it; I'd love to see a better way to do that.

@nebkor
Copy link
Contributor Author

nebkor commented Jul 15, 2025

It seems the formatting defaults for edition 2024 are slightly different than 2021, which is why all those extraneous changes are in there; they were done automatically.

@joshka
Copy link
Member

joshka commented Jul 15, 2025

Perhaps would you mind doing a quick PR for flipping to 2024 edition and then rebasing this change on that.

I'll have to take a deeper look at this to understand the impact on the async changes.

@nebkor
Copy link
Contributor Author

nebkor commented Jul 15, 2025

Perhaps would you mind doing a quick PR for flipping to 2024 edition and then rebasing this change on that.

I'll have to take a deeper look at this to understand the impact on the async changes.

Done! See #143 .

mut events: Events,
query: Option<String>,
) -> Result<()> {
#[tokio::main]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice!

@joshka
Copy link
Member

joshka commented Jul 15, 2025

Added a few small tweaks to the approach:

  • slapped #[tokio::main] on the app::run method instead of manually building the async runtime
  • moved Events::new() into the run method (as it needs the async reactor to run
  • renamed draw() to render() and made it accept Frame instead of DefaultTerminal
  • put the init call that passes the cli query in App::new()

Does this look good to you?

@nebkor
Copy link
Contributor Author

nebkor commented Jul 15, 2025

Added a few small tweaks to the approach:

* slapped `#[tokio::main]` on the app::run method instead of manually building the async runtime

* moved Events::new() into the run method (as it needs the async reactor to run

* renamed draw() to render() and made it accept Frame instead of DefaultTerminal

* put the init call that passes the cli query in App::new()

Does this look good to you?

I love it!

@joshka joshka merged commit 6d35eac into ratatui:main Jul 15, 2025
8 checks passed
@nebkor nebkor deleted the ratatui-run branch July 15, 2025 21:38
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

Successfully merging this pull request may close these issues.

2 participants