pub fn quit() -> CmdExpand description
Creates a command that quits the application.
This command sends a QuitMsg to the program, which will initiate the
shutdown process.
ยงExamples
use bubbletea_rs::{command, Model, Msg, KeyMsg};
use crossterm::event::KeyCode;
struct MyModel;
impl Model for MyModel {
fn init() -> (Self, Option<command::Cmd>) {
(Self {}, None)
}
fn update(&mut self, msg: Msg) -> Option<command::Cmd> {
// Quit when 'q' is pressed
if let Some(key_msg) = msg.downcast_ref::<KeyMsg>() {
if key_msg.key == KeyCode::Char('q') {
return Some(command::quit());
}
}
None
}
fn view(&self) -> String {
"Press 'q' to quit".to_string()
}
}