pub fn window_size() -> CmdExpand description
Creates a command that requests the current window size.
This command sends a RequestWindowSizeMsg to the program. The terminal
will respond with a WindowSizeMsg containing its current dimensions.
This is useful for responsive layouts that adapt to terminal size.
ยงExamples
use bubbletea_rs::{command, Model, Msg, WindowSizeMsg};
struct MyModel {
width: u16,
height: u16,
}
impl Model for MyModel {
fn init() -> (Self, Option<command::Cmd>) {
let model = Self { width: 0, height: 0 };
// Get initial window size
(model, Some(command::window_size()))
}
fn update(&mut self, msg: Msg) -> Option<command::Cmd> {
if let Some(size_msg) = msg.downcast_ref::<WindowSizeMsg>() {
self.width = size_msg.width;
self.height = size_msg.height;
}
None
}
fn view(&self) -> String {
format!("Window size: {}x{}", self.width, self.height)
}
}