mirror of
https://github.com/ratatui/ratatui.git
synced 2025-09-30 22:41:44 +00:00

I was swayed by the arguments about this made by the compiler team In <https://github.com/rust-lang/compiler-team/issues/750> and decided to look at how this organization affects ratatui. I found this reduces the number of lines across the codebase by about 350 and makes the imports more readable and definitely more greppable as you usually only have to read a single line. I've found in the past that maintaining imports regularly leads to merge conflicts which have to be resolved by hand and this change should reduce the likelihood of that happening. Main change is in rustfmt.toml, and the rest is just the result of running `cargo xtask format`. While implementing this, cargo machete brings up that the various backend crates are unused by the example crates. The re-export of each backend crate under ratatui is to make it possible for libs that rely on a specific version of ratatui to use the same version of the backend crate. Apps in general should use the backend crate directly rather than through ratatui as this is less confusing. - Removes all usages of `ratatui::{crossterm, termion, termwiz}`` in the examples. - Adds the backend crate to the dependencies of the examples that use the backend crate directly.
Input Form example
This example demonstrates how to handle input across several form fields (2 strings and an number). It uses an enum to track the focused field, and sends keyboard events to one which is current.
Run this example with:
cargo run -p input-form
This example does not handle things like cursor movement within the line (just keys and backspace). Most apps would benefit from using the following crates for text input rather than directly using strings:
Some more ideas for handling focus can be found in:
focusable
(see also Ratatui forum post)rat-focus
- A useful
Bevy
discssion about focus more generally.