Skip to main content

Module session

Module session 

Source
Expand description

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:

FeatureModuleTriggerScope
Auto session restorecrate::session (this module)Automatic on clean exit / next launchLast-session state only (single slot)
Named arrangementscrate::arrangementsUser-initiated save/restore via UIMultiple 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.

Modules§

capture
Capture current session state from live windows
crash_guard
A panic boundary that preserves the user’s tabs.
restore
Helpers for restoring session state
storage
File I/O for session persistence

Structs§

SessionState
Top-level session state: all windows at the time of save
SessionTab
A single tab in a saved session.
SessionWindow
A single window in the saved session
TabSnapshot
Snapshot of a single tab’s state.

Enums§

SessionPaneNode
Recursive pane tree node for session persistence