Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

Cache native settings; session work & UI updates

RoversXa1a59b333fd6
diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rs
index e56a5b64..c65feec7 100644
--- a/wezterm-gui/src/native_settings.rs
+++ b/wezterm-gui/src/native_settings.rs
@@ -1,7 +1,9 @@
+use parking_lot::Mutex;
use serde::{Deserialize, Serialize};
use std::fs;
use std::io;
use std::path::PathBuf;
+use std::sync::OnceLock;
use window::{Appearance, Connection, ConnectionOps};
pub(crate) const DEFAULT_SETTINGS_FONT_SIZE: f64 = 14.0;
@@ -190,7 +192,13 @@ pub(crate) fn settings_path() -> PathBuf {
.join("settings.json")
}
-pub(crate) fn load() -> ThinkTermNativeSettings {
+static SETTINGS_CACHE: OnceLock<Mutex<ThinkTermNativeSettings>> = OnceLock::new();
+
+fn settings_cache() -> &'static Mutex<ThinkTermNativeSettings> {
+ SETTINGS_CACHE.get_or_init(|| Mutex::new(load_from_disk()))
+}
+
+fn load_from_disk() -> ThinkTermNativeSettings {
let path = settings_path();
match fs::read_to_string(&path) {
Ok(data) => match serde_json::from_str(&data) {
@@ -214,6 +222,16 @@ pub(crate) fn load() -> ThinkTermNativeSettings {
}
}
+pub(crate) fn load() -> ThinkTermNativeSettings {
+ settings_cache().lock().clone()
+}
+
+pub(crate) fn reload_from_disk() -> ThinkTermNativeSettings {
+ let settings = load_from_disk();
+ *settings_cache().lock() = settings.clone();
+ settings
+}
+
pub(crate) fn save(settings: &ThinkTermNativeSettings) -> anyhow::Result<()> {
let path = settings_path();
if let Some(parent) = path.parent() {
@@ -223,6 +241,7 @@ pub(crate) fn save(settings: &ThinkTermNativeSettings) -> anyhow::Result<()> {
let tmp = path.with_extension("json.tmp");
fs::write(&tmp, data)?;
fs::rename(tmp, path)?;
+ *settings_cache().lock() = settings.clone();
Ok(())
}
diff --git a/wezterm-gui/src/project_sessions.rs b/wezterm-gui/src/project_sessions.rs
index 8b4cc1a0..62194916 100644
--- a/wezterm-gui/src/project_sessions.rs
+++ b/wezterm-gui/src/project_sessions.rs
@@ -16,6 +16,7 @@ use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
+use wezterm_term::Progress;
use wezterm_term::TerminalConfiguration;
use wezterm_term::TerminalSize;
@@ -53,6 +54,8 @@ pub struct Session {
pub is_unread: bool,
#[serde(skip)]
pub work_is_running: bool,
+ #[serde(skip)]
+ pub work_needs_attention: bool,
#[serde(default)]
pub work_finished_unseen: bool,
#[serde(default)]
@@ -105,24 +108,23 @@ pub struct ProjectView {
pub struct SessionView {
pub id: SessionId,
pub name: String,
- pub workspace_name: String,
pub is_active: bool,
pub is_materialized: bool,
pub is_pinned: bool,
pub is_unread: bool,
- pub work_finished_unseen: bool,
+ pub work_status: SessionWorkStatus,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SessionWorkStatus {
Idle,
Running,
+ NeedsAttention,
FinishedUnseen,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct SessionWorkChange {
- status: SessionWorkStatus,
changed: bool,
should_persist: bool,
}
@@ -309,10 +311,40 @@ pub fn current_project_from_cwd() -> Project {
}
}
+fn current_project_for_workspace(active_workspace: &str) -> Project {
+ let mut project = current_project_from_cwd();
+ let session = Session::new_initial(
+ project.id.clone(),
+ "main".to_string(),
+ Some(active_workspace.to_string()),
+ );
+ project.active_session_id = Some(session.id.clone());
+ project.sessions.push(session);
+ project
+}
+
pub fn view_for_current_project(
active_workspace: &str,
live_workspaces: &[String],
) -> ProjectSessionView {
+ let store = SESSION_STORE.lock();
+ if let Some(project_id) = store
+ .project_id_for_workspace(active_workspace)
+ .or_else(|| store.active_project_id.clone())
+ .filter(|project_id| {
+ store
+ .projects
+ .iter()
+ .any(|project| &project.id == project_id)
+ })
+ {
+ return store.view_for_project(&project_id, live_workspaces);
+ }
+
+ current_project_for_workspace(active_workspace).view(live_workspaces)
+}
+
+pub fn sync_current_project(active_workspace: &str) -> bool {
let mut store = SESSION_STORE.lock();
let (project_id, mut changed) =
if let Some(project_id) = store.project_id_for_workspace(active_workspace) {
@@ -326,11 +358,10 @@ pub fn view_for_current_project(
store.ensure_current_project(active_workspace)
};
changed |= store.sync_active_workspace(&project_id, active_workspace);
- let view = store.view_for_project(&project_id, live_workspaces);
if changed {
persist_locked(&store);
}
- view
+ changed
}
pub fn create_session(project_id: &str, name: Option<String>) -> SessionId {
@@ -401,13 +432,41 @@ pub fn activate_session_record(
plan
}
-pub fn observe_session_work(session_id: &str, is_working: bool) -> Option<SessionWorkStatus> {
+pub fn refresh_session_work_for_pane(pane_id: PaneId) -> bool {
+ let mux = Mux::get();
+ let Some((_domain_id, window_id, _tab_id)) = mux.resolve_pane_id(pane_id) else {
+ return false;
+ };
+ let Some(window) = mux.get_window(window_id) else {
+ return false;
+ };
+ let workspace = window.get_workspace().to_string();
+ drop(window);
+ refresh_session_work_for_workspace(&workspace)
+}
+
+pub fn refresh_session_work_for_workspace(workspace: &str) -> bool {
+ let observed = scan_workspace_work_status(workspace);
let mut store = SESSION_STORE.lock();
- let change = store.observe_session_work(session_id, is_working)?;
+ let Some(change) = store.observe_session_work_for_workspace(workspace, observed) else {
+ return false;
+ };
if change.should_persist {
- persist_locked(&store);
+ schedule_session_store_persist();
+ }
+ change.changed
+}
+
+pub fn refresh_all_session_work() -> bool {
+ let workspaces = {
+ let store = SESSION_STORE.lock();
+ store.session_workspace_names()
+ };
+ let mut changed = false;
+ for workspace in workspaces {
+ changed |= refresh_session_work_for_workspace(&workspace);
}
- Some(change.status)
+ changed
}
pub fn acknowledge_session_work_for_workspace(workspace: &str) -> bool {
@@ -635,18 +694,34 @@ fn session_views_for_project(
SessionView {
id: session.id.clone(),
name: session.name.clone(),
- workspace_name,
is_active: project_is_active
&& project.active_session_id.as_deref() == Some(&session.id),
is_materialized,
is_pinned: session.is_pinned,
is_unread: session.is_unread,
- work_finished_unseen: session.work_finished_unseen,
+ work_status: session.work_status(),
}
})
.collect()
}
+impl Project {
+ fn view(&self, live_workspaces: &[String]) -> ProjectSessionView {
+ ProjectSessionView {
+ pinned_sessions: vec![],
+ projects: vec![ProjectView {
+ id: self.id.clone(),
+ name: self.name.clone(),
+ is_active: true,
+ sessions_collapsed: self.sessions_collapsed,
+ sessions: session_views_for_project(self, Some(&self.id), live_workspaces),
+ is_remote: is_remote_project(self),
+ distro: None,
+ }],
+ }
+ }
+}
+
impl SessionStore {
fn ensure_current_project(&mut self, active_workspace: &str) -> (ProjectId, bool) {
let current = current_project_from_cwd();
@@ -655,7 +730,7 @@ impl SessionStore {
(project.id.clone(), false)
} else {
let mut project = current;
- let session = Session::new(
+ let session = Session::new_initial(
project.id.clone(),
"main".to_string(),
Some(active_workspace.to_string()),
@@ -986,48 +1061,21 @@ impl SessionStore {
false
}
- fn observe_session_work(
+ fn observe_session_work_for_workspace(
&mut self,
- session_id: &str,
- is_working: bool,
+ workspace: &str,
+ observed: SessionWorkStatus,
) -> Option<SessionWorkChange> {
for project in &mut self.projects {
- if let Some(session) = project
- .sessions
- .iter_mut()
- .find(|session| session.id == session_id)
- {
- if is_working {
- let should_persist = session.work_finished_unseen;
- let changed = !session.work_is_running || session.work_finished_unseen;
- session.work_is_running = true;
- session.work_finished_unseen = false;
- return Some(SessionWorkChange {
- status: SessionWorkStatus::Running,
- changed,
- should_persist,
- });
+ let project_id = project.id.clone();
+ for session in &mut project.sessions {
+ let session_workspace = session
+ .materialized_workspace_name
+ .clone()
+ .unwrap_or_else(|| workspace_name_for_session(&project_id, &session.id));
+ if session_workspace == workspace {
+ return Some(session.observe_work_status(observed));
}
-
- let mut should_persist = false;
- let changed = if session.work_is_running {
- session.work_is_running = false;
- should_persist = !session.work_finished_unseen;
- session.work_finished_unseen = true;
- true
- } else {
- false
- };
- let status = if session.work_finished_unseen {
- SessionWorkStatus::FinishedUnseen
- } else {
- SessionWorkStatus::Idle
- };
- return Some(SessionWorkChange {
- status,
- changed,
- should_persist,
- });
}
}
None
@@ -1043,11 +1091,13 @@ impl SessionStore {
.unwrap_or_else(|| workspace_name_for_session(&project_id, &session.id));
if session_workspace == workspace {
let should_persist = session.work_finished_unseen;
- let changed = session.work_is_running || session.work_finished_unseen;
+ let changed = session.work_is_running
+ || session.work_needs_attention
+ || session.work_finished_unseen;
session.work_is_running = false;
+ session.work_needs_attention = false;
session.work_finished_unseen = false;
return SessionWorkChange {
- status: SessionWorkStatus::Idle,
changed,
should_persist,
};
@@ -1055,12 +1105,29 @@ impl SessionStore {
}
}
SessionWorkChange {
- status: SessionWorkStatus::Idle,
changed: false,
should_persist: false,
}
}
+ fn session_workspace_names(&self) -> Vec<String> {
+ let mut names = Vec::new();
+ for project in &self.projects {
+ for session in &project.sessions {
+ if session.archived {
+ continue;
+ }
+ names.push(
+ session
+ .materialized_workspace_name
+ .clone()
+ .unwrap_or_else(|| workspace_name_for_session(&project.id, &session.id)),
+ );
+ }
+ }
+ names
+ }
+
fn archive_session(&mut self, session_id: &str) -> bool {
for project in &mut self.projects {
if project.active_session_id.as_deref() == Some(session_id) {
@@ -1190,10 +1257,84 @@ impl Session {
is_pinned: false,
is_unread: false,
work_is_running: false,
+ work_needs_attention: false,
work_finished_unseen: false,
archived: false,
}
}
+
+ fn new_initial(project_id: ProjectId, name: String, workspace: Option<String>) -> Self {
+ let id = workspace
+ .as_deref()
+ .map(|workspace| initial_session_id_for_workspace(&project_id, workspace))
+ .unwrap_or_else(|| new_id("session"));
+ Self {
+ id,
+ name,
+ project_id,
+ layout: None,
+ materialized_workspace_name: workspace,
+ last_active_at: now_ts(),
+ is_pinned: false,
+ is_unread: false,
+ work_is_running: false,
+ work_needs_attention: false,
+ work_finished_unseen: false,
+ archived: false,
+ }
+ }
+
+ fn work_status(&self) -> SessionWorkStatus {
+ if self.work_needs_attention {
+ SessionWorkStatus::NeedsAttention
+ } else if self.work_is_running {
+ SessionWorkStatus::Running
+ } else if self.work_finished_unseen {
+ SessionWorkStatus::FinishedUnseen
+ } else {
+ SessionWorkStatus::Idle
+ }
+ }
+
+ fn observe_work_status(&mut self, observed: SessionWorkStatus) -> SessionWorkChange {
+ match observed {
+ SessionWorkStatus::Running => {
+ let should_persist = self.work_finished_unseen;
+ let changed =
+ !self.work_is_running || self.work_needs_attention || self.work_finished_unseen;
+ self.work_is_running = true;
+ self.work_needs_attention = false;
+ self.work_finished_unseen = false;
+ SessionWorkChange {
+ changed,
+ should_persist,
+ }
+ }
+ SessionWorkStatus::NeedsAttention => {
+ let changed = !self.work_needs_attention;
+ self.work_needs_attention = true;
+ SessionWorkChange {
+ changed,
+ should_persist: false,
+ }
+ }
+ SessionWorkStatus::Idle | SessionWorkStatus::FinishedUnseen => {
+ let was_running = self.work_is_running;
+ let had_attention = self.work_needs_attention;
+ let mut should_persist = false;
+ if was_running {
+ should_persist = !self.work_finished_unseen;
+ self.work_finished_unseen = true;
+ }
+ self.work_is_running = false;
+ self.work_needs_attention = false;
+ SessionWorkChange {
+ changed: was_running || had_attention,
+ should_persist,
+ }
+ }
+ }
+ }
}
fn valid_font_scale(font_scale: Option<f64>) -> Option<f64> {
@@ -1627,6 +1768,59 @@ fn project_id_for_path(path: &Path) -> ProjectId {
format!("project-{hash:x}")
}
+fn initial_session_id_for_workspace(project_id: &str, workspace: &str) -> SessionId {
+ let mut hash = 0xcbf29ce484222325u64;
+ for byte in project_id
+ .bytes()
+ .chain(std::iter::once(0))
+ .chain(workspace.bytes())
+ {
+ hash ^= byte as u64;
+ hash = hash.wrapping_mul(0x100000001b3);
+ }
+ format!("session-{hash:x}")
+}
+
+fn scan_workspace_work_status(workspace: &str) -> SessionWorkStatus {
+ let mux = Mux::get();
+ let mut running = false;
+ let mut needs_attention = false;
+ for window_id in mux.iter_windows_in_workspace(workspace) {
+ let Some(window) = mux.get_window(window_id) else {
+ continue;
+ };
+ let tabs = (0..window.len())
+ .filter_map(|idx| window.get_by_idx(idx).cloned())
+ .collect::<Vec<_>>();
+ drop(window);
+
+ for tab in tabs {
+ for pane in tab.iter_all_panes() {
+ match pane.get_progress() {
+ Progress::None => {}
+ Progress::Percentage(_) | Progress::Indeterminate => running = true,
+ Progress::Error(_) => needs_attention = true,
+ }
+ if crate::termwindow::ui::status_icon::split_leading_legacy_progress_marker(
+ &pane.get_title(),
+ )
+ .is_some()
+ {
+ running = true;
+ }
+ }
+ }
+ }
+
+ if needs_attention {
+ SessionWorkStatus::NeedsAttention
+ } else if running {
+ SessionWorkStatus::Running
+ } else {
+ SessionWorkStatus::Idle
+ }
+}
+
fn is_remote_project(project: &Project) -> bool {
project.id.starts_with("ssh-")
|| project.id.starts_with("system-ssh-")
@@ -1740,6 +1934,64 @@ mod tests {
assert!(!loaded.projects[0].sessions[0].work_finished_unseen);
}
+ #[test]
+ fn synthetic_current_project_matches_ensured_project_ids() {
+ let workspace = "workspace-1";
+ let synthetic = current_project_for_workspace(workspace);
+ let synthetic_session_id = synthetic.sessions[0].id.clone();
+
+ let mut store = SessionStore::default();
+ let (project_id, changed) = store.ensure_current_project(workspace);
+
+ assert!(changed);
+ assert_eq!(project_id, synthetic.id);
+ assert_eq!(store.projects[0].sessions[0].id, synthetic_session_id);
+ assert_eq!(
+ store.projects[0].sessions[0]
+ .materialized_workspace_name
+ .as_deref(),
+ Some(workspace)
+ );
+ }
+
+ #[test]
+ fn workspace_work_observation_transitions_to_finished_unseen() {
+ let mut store = SessionStore::default();
+ let session = Session::new(
+ "project-1".to_string(),
+ "main".to_string(),
+ Some("workspace-1".to_string()),
+ );
+ store.projects.push(Project {
+ id: "project-1".to_string(),
+ name: "thinkterm".to_string(),
+ path: PathBuf::from("/tmp/thinkterm"),
+ sessions: vec![session],
+ active_session_id: None,
+ sessions_collapsed: false,
+ });
+
+ let change = store
+ .observe_session_work_for_workspace("workspace-1", SessionWorkStatus::Running)
+ .unwrap();
+ assert!(change.changed);
+ assert!(!change.should_persist);
+ assert_eq!(
+ store.projects[0].sessions[0].work_status(),
+ SessionWorkStatus::Running
+ );
+
+ let change = store
+ .observe_session_work_for_workspace("workspace-1", SessionWorkStatus::Idle)
+ .unwrap();
+ assert!(change.changed);
+ assert!(change.should_persist);
+ assert_eq!(
+ store.projects[0].sessions[0].work_status(),
+ SessionWorkStatus::FinishedUnseen
+ );
+ }
+
#[test]
fn acknowledged_finished_work_persists_but_runtime_running_state_does_not() {
let mut store = SessionStore::default();
diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rs
index 788997e0..7816ad48 100644
--- a/wezterm-gui/src/settings_window.rs
+++ b/wezterm-gui/src/settings_window.rs
@@ -630,6 +630,7 @@ struct SettingsUiState {
search: TextInputState,
font_size_input: TextInputState,
font_family_input: TextInputState,
+ font_family_input_dirty: bool,
interaction: InteractionState<SettingsAction>,
drag: Option<SettingsDrag>,
open_dropdown: Option<SettingsDropdown>,
@@ -658,6 +659,7 @@ impl SettingsUiState {
search: TextInputState::new(),
font_size_input: TextInputState::new(),
font_family_input: TextInputState::new(),
+ font_family_input_dirty: false,
interaction: InteractionState::default(),
drag: None,
open_dropdown: None,
@@ -1140,10 +1142,12 @@ impl SettingsWindow {
fn dispatch(&mut self, event: WindowEvent, window: &Window) -> anyhow::Result<bool> {
match event {
WindowEvent::CloseRequested => {
+ self.commit_focused_input();
window.close();
Ok(true)
}
WindowEvent::Destroyed => {
+ self.commit_focused_input();
self.ui.memory_monitoring = false;
self.ui.memory_monitor_generation =
self.ui.memory_monitor_generation.wrapping_add(1);
@@ -1230,10 +1234,11 @@ impl SettingsWindow {
self.ui.interaction.pressed = action;
match action {
Some(SettingsAction::SearchInput | SettingsAction::FontFamilyInput) => {
- self.ui.interaction.focused = action;
+ self.set_focused_input(action);
self.ui.open_dropdown = None;
}
Some(SettingsAction::SidebarResize) => {
+ self.set_focused_input(None);
self.ui.drag = Some(SettingsDrag::SidebarResize {
start_x: x,
start_width: self.ui.sidebar.width,
@@ -1248,14 +1253,14 @@ impl SettingsWindow {
| SettingsAction::ToggleMainRendererMenu
| SettingsAction::SetMainRenderer(_),
) => {
- self.ui.interaction.focused = None;
+ self.set_focused_input(None);
}
Some(_) => {
- self.ui.interaction.focused = None;
+ self.set_focused_input(None);
self.ui.open_dropdown = None;
}
None => {
- self.ui.interaction.focused = None;
+ self.set_focused_input(None);
self.ui.open_dropdown = None;
}
}
@@ -1512,7 +1517,7 @@ impl SettingsWindow {
self.backspace_focused_input(focused)
}
KeyCode::Char('\u{1b}') | KeyCode::Char('\r') => {
- self.ui.interaction.focused = None;
+ self.set_focused_input(None);
true
}
KeyCode::Char(ch) => {
@@ -1571,7 +1576,7 @@ impl SettingsWindow {
let Some(text) = self.ui.font_family_input.take_selected_text() else {
return false;
};
- self.sync_native_terminal_inputs();
+ self.ui.font_family_input_dirty = true;
text
}
_ => return false,
@@ -1619,7 +1624,7 @@ impl SettingsWindow {
}
SettingsAction::FontFamilyInput => {
self.ui.font_family_input.backspace();
- self.sync_native_terminal_inputs();
+ self.ui.font_family_input_dirty = true;
true
}
_ => false,
@@ -1636,21 +1641,45 @@ impl SettingsWindow {
}
SettingsAction::FontFamilyInput => {
self.ui.font_family_input.push_text(text);
- self.sync_native_terminal_inputs();
+ self.ui.font_family_input_dirty = true;
true
}
_ => false,
}
}
- fn sync_native_terminal_inputs(&mut self) {
+ fn set_focused_input(&mut self, focused: Option<SettingsAction>) {
+ if self.ui.interaction.focused != focused {
+ self.commit_focused_input();
+ }
+ self.ui.interaction.focused = focused;
+ }
+
+ fn commit_focused_input(&mut self) {
+ if self.ui.interaction.focused == Some(SettingsAction::FontFamilyInput)
+ && self.commit_native_terminal_inputs_from_ui()
+ {
+ self.save_and_apply_native_terminal_settings();
+ }
+ }
+
+ fn commit_native_terminal_inputs_from_ui(&mut self) -> bool {
+ if !self.ui.font_family_input_dirty {
+ return false;
+ }
+ self.ui.font_family_input_dirty = false;
+
let family = self.ui.font_family_input.text.trim();
- self.native_settings.terminal.font_family = if family.is_empty() {
+ let next = if family.is_empty() {
None
} else {
Some(family.to_string())
};
- self.save_and_apply_native_terminal_settings();
+ if self.native_settings.terminal.font_family == next {
+ return false;
+ }
+ self.native_settings.terminal.font_family = next;
+ true
}
fn sync_selected_section_with_search(&mut self) {
@@ -1957,6 +1986,7 @@ impl SettingsWindow {
fn perform_action(&mut self, action: SettingsAction, window: &Window) {
match action {
SettingsAction::Select(section) => {
+ self.commit_focused_input();
self.selected = section;
self.ui.content_scroll.reset();
self.ui.open_dropdown = None;
@@ -2226,7 +2256,7 @@ impl SettingsWindow {
}
}
SettingsAction::SearchInput => {
- self.ui.interaction.focused = Some(SettingsAction::SearchInput);
+ self.set_focused_input(Some(SettingsAction::SearchInput));
}
SettingsAction::DecreaseFontSize => self.step_terminal_font_size(-1.0),
SettingsAction::IncreaseFontSize => self.step_terminal_font_size(1.0),
@@ -2238,13 +2268,13 @@ impl SettingsWindow {
SettingsAction::IncreaseSettingsFontWeight => self.step_settings_font_weight(100),
SettingsAction::ResetSettingsFontWeight => self.reset_settings_font_weight(),
SettingsAction::FontFamilyInput => {
- self.ui.interaction.focused = Some(SettingsAction::FontFamilyInput);
+ self.set_focused_input(Some(SettingsAction::FontFamilyInput));
}
SettingsAction::ClearSearch => {
self.ui.search.clear();
self.ui.sidebar_scroll.reset();
self.sync_selected_section_with_search();
- self.ui.interaction.focused = Some(SettingsAction::SearchInput);
+ self.set_focused_input(Some(SettingsAction::SearchInput));
}
SettingsAction::SidebarResize
| SettingsAction::SidebarScrollArea
@@ -5899,7 +5929,7 @@ impl SettingsWindow {
}
fn load_native_settings() -> ThinkTermNativeSettings {
- crate::native_settings::load()
+ crate::native_settings::reload_from_disk()
}
fn config_source_summary() -> String {
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 77e6466c..0fb34b87 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -1272,6 +1272,7 @@ impl TermWindow {
myself.apply_native_terminal_settings();
myself.apply_workspace_session_font_scales();
myself.load_os_parameters();
+ myself.sync_current_project_session();
window.show();
myself.subscribe_to_pane_updates();
myself.emit_window_event("window-config-reloaded", None);
@@ -1595,19 +1596,25 @@ impl TermWindow {
alert: Alert::SetUserVar { name, value },
pane_id,
} => {
+ self.refresh_session_work_for_pane(pane_id);
self.emit_user_var_event(pane_id, name, value);
}
MuxNotification::WindowTitleChanged { .. }
| MuxNotification::Alert {
+ alert: Alert::OutputSinceFocusLost | Alert::CurrentWorkingDirectoryChanged,
+ ..
+ } => {
+ self.update_title();
+ }
+ MuxNotification::Alert {
alert:
- Alert::OutputSinceFocusLost
- | Alert::CurrentWorkingDirectoryChanged
- | Alert::WindowTitleChanged(_)
+ Alert::WindowTitleChanged(_)
| Alert::TabTitleChanged(_)
| Alert::IconTitleChanged(_)
| Alert::Progress(_),
- ..
+ pane_id,
} => {
+ self.refresh_session_work_for_pane(pane_id);
self.update_title();
}
MuxNotification::Alert {
@@ -1693,8 +1700,9 @@ impl TermWindow {
MuxNotification::SaveToDownloads { .. } => {
// Handled by frontend
}
- MuxNotification::PaneFocused(_) => {
+ MuxNotification::PaneFocused(pane_id) => {
// Also handled by clientpane
+ self.refresh_session_work_for_pane(pane_id);
self.update_title_post_status();
}
MuxNotification::TabResized(_) => {
@@ -1704,16 +1712,23 @@ impl TermWindow {
MuxNotification::TabTitleChanged { .. } => {
self.update_title_post_status();
}
- MuxNotification::PaneAdded(_)
- | MuxNotification::WorkspaceRenamed { .. }
- | MuxNotification::PaneRemoved(_)
+ MuxNotification::PaneAdded(pane_id) => {
+ self.refresh_session_work_for_pane(pane_id);
+ }
+ MuxNotification::PaneRemoved(_) => {
+ self.refresh_all_session_work();
+ }
+ MuxNotification::WorkspaceRenamed { .. }
| MuxNotification::WindowWorkspaceChanged(_)
| MuxNotification::ActiveWorkspaceChanged(_)
- | MuxNotification::Empty
- | MuxNotification::WindowCreated(_) => {}
+ | MuxNotification::WindowCreated(_) => {
+ self.sync_current_project_session();
+ }
+ MuxNotification::Empty => {}
},
TermWindowNotif::EmitStatusUpdate => {
self.emit_status_event();
+ self.refresh_all_session_work();
}
TermWindowNotif::OpenProjectPath(path) => {
let path = path.to_string_lossy();
@@ -1751,6 +1766,7 @@ impl TermWindow {
tab.resize(self.terminal_size);
}
};
+ self.sync_current_project_session();
self.update_title();
window.invalidate();
}
@@ -1981,6 +1997,37 @@ impl TermWindow {
self.emit_window_event("update-status", None);
}
+ fn invalidate_window_if(&self, should_invalidate: bool) {
+ if should_invalidate {
+ if let Some(window) = self.window.as_ref() {
+ window.invalidate();
+ }
+ }
+ }
+
+ fn current_mux_workspace(&self) -> Option<String> {
+ Mux::get()
+ .get_window(self.mux_window_id)
+ .map(|window| window.get_workspace().to_string())
+ }
+
+ fn sync_current_project_session(&mut self) {
+ let Some(workspace) = self.current_mux_workspace() else {
+ return;
+ };
+ self.invalidate_window_if(crate::project_sessions::sync_current_project(&workspace));
+ }
+
+ fn refresh_session_work_for_pane(&mut self, pane_id: PaneId) {
+ self.invalidate_window_if(crate::project_sessions::refresh_session_work_for_pane(
+ pane_id,
+ ));
+ }
+
+ fn refresh_all_session_work(&mut self) {
+ self.invalidate_window_if(crate::project_sessions::refresh_all_session_work());
+ }
+
fn schedule_window_event(&mut self, name: &str, pane_id: Option<PaneId>) {
let window = GuiWin::new(self);
let pane = match pane_id {
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index a88883f8..0275e390 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -406,6 +406,7 @@ impl super::TermWindow {
fn wheel_amount(event: &MouseEvent) -> Option<i16> {
match event.kind {
WMEK::HorzWheel(amount) => Some(amount),
+ WMEK::VertWheel(amount) => Some(amount),
_ => None,
}
}
@@ -1700,8 +1701,9 @@ impl super::TermWindow {
self.scroll_pane_nav_tabs(pane_id, amount, context);
return;
}
- WMEK::VertWheel(_) => {
+ WMEK::VertWheel(amount) => {
self.lock_pane_nav_tab_wheel_surface(pane_id);
+ self.scroll_pane_nav_tabs(pane_id, amount, context);
return;
}
_ => {}
diff --git a/wezterm-gui/src/termwindow/render/pane.rs b/wezterm-gui/src/termwindow/render/pane.rs
index 1bdff7d2..68935f09 100644
--- a/wezterm-gui/src/termwindow/render/pane.rs
+++ b/wezterm-gui/src/termwindow/render/pane.rs
@@ -351,15 +351,19 @@ impl crate::TermWindow {
}
}
- let close_x = draw_tab_x
+ let raw_close_x = draw_tab_x
.saturating_add(tab_width)
.saturating_sub(button_size + TAB_CLOSE_RIGHT_GAP);
let close_slot_reserved = !is_renaming_tab;
- let show_close = close_slot_reserved && (selected_tab || is_hovered);
- if show_close
- && close_x >= tab_start
- && close_x.saturating_add(button_size) <= max_tab_right
- {
+ let close_view_left = draw_tab_x.max(tab_start);
+ let close_view_right = draw_tab_x.saturating_add(tab_width).min(max_tab_right);
+ let close_x = raw_close_x
+ .min(close_view_right.saturating_sub(button_size))
+ .max(close_view_left);
+ let show_close = close_slot_reserved
+ && (selected_tab || is_hovered)
+ && close_view_right.saturating_sub(close_view_left) >= button_size;
+ if show_close {
let close_hovered =
self.is_pointer_over_ui_rect(close_x, tab_y, button_size, button_size);
if close_hovered {
@@ -417,7 +421,11 @@ impl crate::TermWindow {
let ui_metrics = RenderMetrics::with_font_metrics(&ui_font.metrics());
let text_x = title_icon_x + icon_size + PANE_NAV_ICON_GAP;
let text_right = if close_slot_reserved {
- close_x
+ if show_close {
+ close_x
+ } else {
+ raw_close_x
+ }
} else {
draw_tab_x + tab_width - PANE_NAV_INSET
};
@@ -698,62 +706,67 @@ impl crate::TermWindow {
}
}
- let close_x = draw_tab_x
+ let raw_close_x = draw_tab_x
.saturating_add(tab_width)
.saturating_sub(button_size + TAB_CLOSE_RIGHT_GAP);
let close_slot_reserved = !is_renaming_tab;
- let show_close = close_slot_reserved && (selected_tab || is_hovered);
+ let close_view_left = draw_tab_x.max(tab_start);
+ let close_view_right = draw_tab_x.saturating_add(tab_width).min(max_tab_right);
+ let close_x = raw_close_x
+ .min(close_view_right.saturating_sub(button_size))
+ .max(close_view_left);
+ let show_close = close_slot_reserved
+ && (selected_tab || is_hovered)
+ && close_view_right.saturating_sub(close_view_left) >= button_size;
if show_close {
- if close_x >= tab_start && close_x.saturating_add(button_size) <= max_tab_right {
- let close_hovered =
- self.is_pointer_over_ui_rect(close_x, tab_y, button_size, button_size);
- if close_hovered {
- let hover_alpha = if self.is_pointer_pressing_ui_rect(
- close_x,
- tab_y,
- button_size,
- button_size,
- ) {
- 0.20
- } else {
- 0.12
- };
- let hover_inset = TAB_CLOSE_HOVER_INSET.min(button_size / 2);
- let hover_size = button_size.saturating_sub(hover_inset * 2);
- self.fill_rounded_rectangle(
- layers,
- 1,
- euclid::rect(
- (close_x + hover_inset) as f32,
- (tab_y + hover_inset) as f32,
- hover_size as f32,
- hover_size as f32,
- ),
- foreground.mul_alpha(hover_alpha),
- TAB_CLOSE_HOVER_RADIUS,
- )
- .context("pane nav close hover")?;
- }
- self.ui_items.push(UIItem {
- x: close_x,
- y: tab_y,
- width: button_size,
- height: button_size,
- item_type: UIItemType::PaneNav {
- pane_id: pos.pane.pane_id(),
- pane_index: pos.index,
- action: PaneNavAction::Close(tab.pane_id),
- },
- });
- self.paint_pane_nav_icon(
+ let close_hovered =
+ self.is_pointer_over_ui_rect(close_x, tab_y, button_size, button_size);
+ if close_hovered {
+ let hover_alpha = if self.is_pointer_pressing_ui_rect(
+ close_x,
+ tab_y,
+ button_size,
+ button_size,
+ ) {
+ 0.20
+ } else {
+ 0.12
+ };
+ let hover_inset = TAB_CLOSE_HOVER_INSET.min(button_size / 2);
+ let hover_size = button_size.saturating_sub(hover_inset * 2);
+ self.fill_rounded_rectangle(
layers,
- SvgIcon::X,
- close_x + ((button_size.saturating_sub(icon_size)) / 2),
- title_icon_y,
- icon_size,
- if close_hovered { foreground } else { muted_fg },
- )?;
+ 1,
+ euclid::rect(
+ (close_x + hover_inset) as f32,
+ (tab_y + hover_inset) as f32,
+ hover_size as f32,
+ hover_size as f32,
+ ),
+ foreground.mul_alpha(hover_alpha),
+ TAB_CLOSE_HOVER_RADIUS,
+ )
+ .context("pane nav close hover")?;
}
+ self.ui_items.push(UIItem {
+ x: close_x,
+ y: tab_y,
+ width: button_size,
+ height: button_size,
+ item_type: UIItemType::PaneNav {
+ pane_id: pos.pane.pane_id(),
+ pane_index: pos.index,
+ action: PaneNavAction::Close(tab.pane_id),
+ },
+ });
+ self.paint_pane_nav_icon(
+ layers,
+ SvgIcon::X,
+ close_x + ((button_size.saturating_sub(icon_size)) / 2),
+ title_icon_y,
+ icon_size,
+ if close_hovered { foreground } else { muted_fg },
+ )?;
}
let ui_font = self
@@ -763,7 +776,11 @@ impl crate::TermWindow {
let ui_metrics = RenderMetrics::with_font_metrics(&ui_font.metrics());
let text_x = title_icon_x + icon_size + PANE_NAV_ICON_GAP;
let text_right = if close_slot_reserved {
- close_x
+ if show_close {
+ close_x
+ } else {
+ raw_close_x
+ }
} else {
draw_tab_x + tab_width - PANE_NAV_INSET
};
diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rs
index 1d6672dd..68d54266 100644
--- a/wezterm-gui/src/termwindow/ui/sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs
@@ -6,7 +6,7 @@ use crate::termwindow::render::corners::{
TOP_RIGHT_ROUNDED_CORNER,
};
use crate::termwindow::ui::icons::{distro_to_icon, BrandIcon, SvgIcon};
-use crate::termwindow::ui::status_icon::{split_leading_legacy_progress_marker, UiStatusKind};
+use crate::termwindow::ui::status_icon::UiStatusKind;
use crate::termwindow::ui::tokens::{
CAPSULE_BORDER_WIDTH, MACOS_TITLEBAR_CONTENT_TOP_INSET, SIDEBAR_ICON_GAP, SIDEBAR_INSET,
SIDEBAR_MAX_WIDTH, SIDEBAR_MIN_WIDTH, SIDEBAR_RESIZE_HANDLE_WIDTH, SIDEBAR_ROW_GAP,
@@ -238,52 +238,13 @@ impl crate::TermWindow {
&self,
session: &project_sessions::SessionView,
) -> Option<UiStatusKind> {
- let mux = Mux::get();
- let mut is_working = false;
- let mut needs_attention = false;
- for window_id in mux.iter_windows_in_workspace(&session.workspace_name) {
- let Some(window) = mux.get_window(window_id) else {
- continue;
- };
- let tabs = (0..window.len())
- .filter_map(|idx| window.get_by_idx(idx).cloned())
- .collect::<Vec<_>>();
- drop(window);
-
- for tab in tabs {
- for pane in tab.iter_all_panes() {
- match UiStatusKind::from_progress(&pane.get_progress()) {
- Some(UiStatusKind::Running) => is_working = true,
- Some(UiStatusKind::NeedsAttention) => needs_attention = true,
- Some(UiStatusKind::Done) | None => {}
- }
- if split_leading_legacy_progress_marker(&pane.get_title()).is_some() {
- is_working = true;
- }
- }
- }
- }
-
- if is_working {
- project_sessions::observe_session_work(&session.id, true);
- return Some(UiStatusKind::Running);
- }
-
- if needs_attention {
- return Some(UiStatusKind::NeedsAttention);
- }
-
- let status = project_sessions::observe_session_work(&session.id, false).unwrap_or({
- if session.work_finished_unseen {
- project_sessions::SessionWorkStatus::FinishedUnseen
- } else {
- project_sessions::SessionWorkStatus::Idle
+ match session.work_status {
+ project_sessions::SessionWorkStatus::Running => Some(UiStatusKind::Running),
+ project_sessions::SessionWorkStatus::NeedsAttention => {
+ Some(UiStatusKind::NeedsAttention)
}
- });
- match status {
project_sessions::SessionWorkStatus::FinishedUnseen => Some(UiStatusKind::Done),
- project_sessions::SessionWorkStatus::Idle
- | project_sessions::SessionWorkStatus::Running => None,
+ project_sessions::SessionWorkStatus::Idle => None,
}
}