pub mod capture;
pub mod crash_guard;
pub mod restore;
pub mod storage;
pub use par_term_config::snapshot_types::{SessionPaneNode, TabSnapshot};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionState {
pub saved_at: String,
pub windows: Vec<SessionWindow>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SessionWindow {
pub position: (i32, i32),
pub size: (u32, u32),
pub tabs: Vec<SessionTab>,
pub active_tab_index: usize,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tmux_session_name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub mux_session_name: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(transparent)]
pub struct SessionTab {
pub snapshot: TabSnapshot,
}
#[cfg(test)]
mod pane_title_persistence_tests {
use super::SessionPaneNode;
#[test]
fn leaf_user_title_round_trips_and_old_files_load() {
let leaf = SessionPaneNode::Leaf {
cwd: Some("/tmp".to_string()),
user_title: Some("build box".to_string()),
};
let yaml = serde_yaml_ng::to_string(&leaf).expect("serialize");
let back: SessionPaneNode = serde_yaml_ng::from_str(&yaml).expect("deserialize");
let SessionPaneNode::Leaf { cwd, user_title } = back else {
panic!("round-trip must stay a leaf")
};
assert_eq!(cwd.as_deref(), Some("/tmp"));
assert_eq!(
user_title.as_deref(),
Some("build box"),
"the user title must survive the YAML round-trip"
);
assert!(
!yaml.contains("user_title: null"),
"absent titles are omitted"
);
let untitled = SessionPaneNode::Leaf {
cwd: Some("/tmp".to_string()),
user_title: None,
};
let old_yaml = serde_yaml_ng::to_string(&untitled).expect("serialize untitled");
assert!(
!old_yaml.contains("user_title"),
"an absent title is not written: {old_yaml}"
);
let parsed: SessionPaneNode =
serde_yaml_ng::from_str(&old_yaml).expect("old-format leaf loads");
let SessionPaneNode::Leaf { cwd, user_title } = parsed else {
panic!("old-format parse must stay a leaf")
};
assert_eq!(cwd.as_deref(), Some("/tmp"));
assert_eq!(user_title, None);
}
}