par_term/session/mod.rs
1//! Session state types for save/restore on startup
2//!
3//! This module provides automatic session persistence: save the current window
4//! layout, tabs, and pane splits on clean exit, then restore them on next launch.
5
6pub mod capture;
7pub mod restore;
8pub mod storage;
9
10use crate::pane::SplitDirection;
11use serde::{Deserialize, Serialize};
12
13/// Top-level session state: all windows at the time of save
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct SessionState {
16 /// Timestamp when the session was saved (ISO 8601)
17 pub saved_at: String,
18 /// All windows in the session
19 pub windows: Vec<SessionWindow>,
20}
21
22/// A single window in the saved session
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct SessionWindow {
25 /// Window position (x, y) in physical pixels
26 pub position: (i32, i32),
27 /// Window size (width, height) in physical pixels
28 pub size: (u32, u32),
29 /// Tabs in this window
30 pub tabs: Vec<SessionTab>,
31 /// Index of the active tab
32 pub active_tab_index: usize,
33}
34
35/// A single tab in a saved session
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct SessionTab {
38 /// Working directory of the primary/focused pane
39 pub cwd: Option<String>,
40 /// Tab title
41 pub title: String,
42 /// Pane layout tree (None = single pane, use cwd above)
43 #[serde(default, skip_serializing_if = "Option::is_none")]
44 pub pane_layout: Option<SessionPaneNode>,
45}
46
47/// Recursive pane tree node for session persistence
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub enum SessionPaneNode {
50 /// A terminal pane leaf
51 Leaf {
52 /// Working directory of this pane
53 cwd: Option<String>,
54 },
55 /// A split containing two children
56 Split {
57 /// Split direction
58 direction: SplitDirection,
59 /// Split ratio (0.0-1.0)
60 ratio: f32,
61 /// First child (top/left)
62 first: Box<SessionPaneNode>,
63 /// Second child (bottom/right)
64 second: Box<SessionPaneNode>,
65 },
66}