1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-22 12:17:19 +03:00

trigger the status event when the title is updated, too

This makes it quicker to respond to things like eg: the cwd
in the pane changing.

refs: https://github.com/wez/wezterm/issues/500
This commit is contained in:
Wez Furlong 2021-03-02 22:36:39 -08:00
parent 9ac230876c
commit c305abdcd7
2 changed files with 36 additions and 3 deletions

View File

@ -49,8 +49,10 @@ impl UserData for GuiWin {
methods.add_method("window_id", |_, this, _: ()| Ok(this.mux_window_id));
methods.add_async_method("set_right_status", |_, this, status: String| async move {
this.with_term_window(move |term_window, _ops| {
term_window.right_status = status.clone();
term_window.update_title();
if status != term_window.right_status {
term_window.right_status = status.clone();
term_window.update_title_post_status();
}
Ok(())
})
.await

View File

@ -505,6 +505,23 @@ impl TermWindow {
Ok(())
}
fn schedule_status_update(&self) {
if let Some(window) = self.window.as_ref() {
let window = window.clone();
promise::spawn::spawn(async move {
window
.apply(move |tw, ops| {
if let Some(term_window) = tw.downcast_mut::<TermWindow>() {
term_window.emit_status_event(ops)?;
}
Ok(())
})
.await
})
.detach();
}
}
fn start_periodic_maintenance(window: Window) {
Connection::get()
.unwrap()
@ -762,7 +779,21 @@ impl TermWindow {
}
}
pub fn update_title(&mut self) {
/// Called by various bits of code to update the title bar.
/// Let's also trigger the status event so that it can choose
/// to update the right-status.
fn update_title(&mut self) {
self.schedule_status_update();
self.update_title_impl();
}
/// Called by window:set_right_status after the status has
/// been updated; let's update the bar
pub fn update_title_post_status(&mut self) {
self.update_title_impl();
}
fn update_title_impl(&mut self) {
let mux = Mux::get().unwrap();
let window = match mux.get_window(self.mux_window_id) {
Some(window) => window,