1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! Session state types for save/restore on startup.
//!
//! This module provides **automatic session persistence**: save the current window
//! layout, tabs, and pane splits on clean exit, then restore them on next launch.
//!
//! # Relationship to `crate::arrangements`
//!
//! par-term has two overlapping session persistence mechanisms:
//!
//! | Feature | Module | Trigger | Scope |
//! |---------|--------|---------|-------|
//! | Auto session restore | `crate::session` (this module) | Automatic on clean exit / next launch | Last-session state only (single slot) |
//! | Named arrangements | `crate::arrangements` | User-initiated save/restore via UI | Multiple named snapshots, monitor-aware |
//!
//! Both capture window positions, sizes, tab CWDs, and tab titles using similar
//! serialization patterns (serde JSON via `storage` submodule). The key distinction
//! is lifecycle: session state is ephemeral (overwritten on each clean exit), while
//! arrangements are user-named and persist indefinitely.
//!
//! # Crash recovery
//!
//! Neither of those survives a panic: both are written on the way out, and a
//! panicking process never gets there. [`crash_guard`] adds a third file,
//! `crash_session.yaml`, written from a panic hook out of a snapshot the event
//! loop publishes periodically. It is deliberately a separate file — a process
//! that has just panicked must not overwrite the good session — and
//! `WindowManager::restore_session` prefers it when present, then deletes it.
//! Read that module's header before changing anything here: it is explicit about
//! which panic classes it covers and which it cannot.
//!
//! # Shared types
//!
//! The common per-tab fields (`cwd`, `title`, `custom_color`, `user_title`,
//! `custom_icon`) are defined once in [`par_term_config::snapshot_types::TabSnapshot`]
//! and are embedded into [`SessionTab`] via `#[serde(flatten)]`. The arrangements
//! module re-exports the same type directly, eliminating the previous duplication.
//! Existing YAML session files are fully backward-compatible — all fields remain at
//! the same nesting level.
// Re-export TabSnapshot so session consumers can use `crate::session::TabSnapshot`.
use crateSplitDirection;
pub use TabSnapshot;
use ;
/// Top-level session state: all windows at the time of save
/// A single window in the saved session
/// A single tab in a saved session.
///
/// The common tab fields (`cwd`, `title`, `custom_color`, `user_title`,
/// `custom_icon`) are inherited from [`TabSnapshot`] via `#[serde(flatten)]`
/// so that the serialized YAML layout is unchanged from before this refactor.
/// The session-specific field `pane_layout` is appended alongside the flattened
/// fields in the output.
/// Recursive pane tree node for session persistence