set_window_title

Function set_window_title 

Source
pub fn set_window_title(title: String) -> Cmd
Expand description

Creates a command that sets the terminal window title.

This command sends a SetWindowTitleMsg to the program, which will update the terminal window’s title. Note that not all terminals support this feature.

§Arguments

  • title - The new window title

§Examples

use bubbletea_rs::{command, Model, Msg};

struct MyModel {
    app_name: String,
    document_name: Option<String>,
}

impl Model for MyModel {
    fn init() -> (Self, Option<command::Cmd>) {
        let model = Self {
            app_name: "My App".to_string(),
            document_name: None,
        };
        // Set initial window title
        let cmd = command::set_window_title(model.app_name.clone());
        (model, Some(cmd))
    }

    fn update(&mut self, msg: Msg) -> Option<command::Cmd> {
        // In a real app, you'd check for document open messages
        // Update title when document changes
        if let Some(doc_name) = &self.document_name {
            let title = format!("{} - {}", doc_name, self.app_name);
            return Some(command::set_window_title(title));
        }
        None
    }
     
    fn view(&self) -> String {
        match &self.document_name {
            Some(doc) => format!("Editing: {}", doc),
            None => "No document open".to_string(),
        }
    }
}