pub fn run(f: impl FnMut(&mut Context)) -> Result<()>Available on crate feature
crossterm only.Expand description
Run the TUI loop with default configuration.
Enters alternate screen mode, runs f each frame, and exits cleanly on
Ctrl+C or when Context::quit is called.
§Raw mode is handled for you
SLT enters raw mode automatically inside run / run_with /
run_inline / run_async. Wrapping these with manual
crossterm::terminal::enable_raw_mode() and disable_raw_mode() is
redundant — the calls are idempotent so no harm comes of it, but it
suggests a misunderstood lifecycle. Drop the wrapper calls:
// Don't do this — it's already handled internally:
// crossterm::terminal::enable_raw_mode()?;
slt::run(|ui| { ui.text("hi"); })?;
// crossterm::terminal::disable_raw_mode()?;§Ctrl+C opt-out (issue #238)
By default, Ctrl+C exits the loop cleanly — matching the v0.19 contract
and the convention most TUIs follow. To match RataTUI’s raw-mode
semantics (Ctrl+C delivered as a regular Event::Key), set
RunConfig::handle_ctrl_c(false) and decide
inside the frame closure whether to call Context::quit:
use slt::{KeyModifiers, RunConfig};
slt::run_with(RunConfig::default().handle_ctrl_c(false), |ui| {
if ui.key_mod('c', KeyModifiers::CONTROL) {
// e.g. clear input, prompt to save, then quit:
ui.quit();
}
})?;§Example
fn main() -> std::io::Result<()> {
slt::run(|ui| {
ui.text("Press Ctrl+C to exit");
})
}