You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(snapshot/README): Comprehensive overhaul with doctest integration
why: Improve documentation clarity, educational value, and test coverage
what: - Added concise TL;DR and Quick Start sections - Reorganized value propositions into logical groups - Created visual ASCII hierarchy diagram - Converted all examples to runnable doctests (19 tests passing) - Added callout boxes for key features (immutability, filtering) - Improved navigation examples with proper error handling - Added comprehensive Best Practices section - Ensured examples work in minimal test environments
Copy file name to clipboardExpand all lines: src/libtmux/snapshot/README.md
+65-8
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,27 @@
1
1
# libtmux Snapshot Module
2
2
3
+
> **TL;DR:** Create immutable, point-in-time captures of your tmux environment. Snapshots let you inspect, filter, compare, and store tmux state without modifying the live server. Perfect for testing, automation, and state recovery.
4
+
3
5
The snapshot module provides a powerful way to capture the state of tmux objects (Server, Session, Window, Pane) as immutable, hierarchical snapshots. These snapshots preserve the structure and relationships between tmux objects while allowing for inspection, filtering, and serialization.
4
6
5
7
## Value Proposition
6
8
7
9
Snapshots provide several key benefits for tmux automation and management:
8
10
9
-
-**Point-in-time Captures**: Create immutable records of tmux state at specific moments
10
-
-**State Inspection**: Examine the structure of sessions, windows, and panes without modifying them
11
-
-**Testing Support**: Build reliable tests with deterministic tmux state snapshots
12
-
-**Comparison & Diff**: Compare configurations between different sessions or before/after changes
13
-
-**State Serialization**: Convert tmux state to dictionaries for storage or analysis
14
-
-**Safety & Predictability**: Work with tmux state without modifying the actual tmux server
15
-
-**Content Preservation**: Optionally capture pane content to preserve terminal output
16
-
-**Filtering & Searching**: Find specific components within complex tmux arrangements
11
+
### Safe State Handling
12
+
-**Immutable Captures:** Create read-only records of tmux state at specific points in time
13
+
-**Safety & Predictability:** Work with tmux state without modifying the actual tmux server
14
+
-**Content Preservation:** Optionally capture pane content to preserve terminal output
15
+
16
+
### Testing & Automation
17
+
-**Testing Support:** Build reliable tests with deterministic tmux state snapshots
18
+
-**Comparison & Diff:** Compare configurations between different sessions or before/after changes
19
+
-**State Backup:** Create safety checkpoints before risky operations
20
+
21
+
### Analysis & Discovery
22
+
-**Hierarchical Navigation:** Traverse sessions, windows, and panes with consistent object APIs
23
+
-**Filtering & Searching:** Find specific components within complex tmux arrangements
24
+
-**Dictionary Conversion:** Serialize tmux state for storage or analysis
17
25
18
26
## Installation
19
27
@@ -23,6 +31,51 @@ The snapshot module is included with libtmux:
23
31
pip install libtmux
24
32
```
25
33
34
+
## Quick Start
35
+
36
+
Here's how to quickly get started with snapshots:
37
+
38
+
```python
39
+
# Import the snapshot module
40
+
from libtmux.snapshot.factory import create_snapshot
41
+
from libtmux import Server
42
+
43
+
# Connect to the tmux server and create a snapshot
filtered = snapshot.filter(lambdaobj: hasattr(obj, "name") and obj.name =="my-session")
57
+
58
+
# Convert to dictionary for serialization
59
+
state_dict = snapshot.to_dict()
60
+
```
61
+
62
+
### Snapshot Hierarchy
63
+
64
+
Snapshots maintain the same structure and relationships as live tmux objects:
65
+
66
+
```
67
+
ServerSnapshot
68
+
├── Session 1
69
+
│ ├── Window 1
70
+
│ │ ├── Pane 1 (with optional content)
71
+
│ │ └── Pane 2 (with optional content)
72
+
│ └── Window 2
73
+
│ └── Pane 1 (with optional content)
74
+
└── Session 2
75
+
└── Window 1
76
+
└── Pane 1 (with optional content)
77
+
```
78
+
26
79
## Basic Usage
27
80
28
81
Creating snapshots is straightforward using the factory functions:
@@ -63,6 +116,8 @@ True
63
116
>>># This makes snapshots ideal for "before/after" comparisons in testing
64
117
```
65
118
119
+
> **KEY FEATURE:** Snapshots are completely *immutable* and detached from the live tmux server. Any changes you make to the real tmux environment won't affect your snapshots, making them perfect for state comparison or reference points.
120
+
66
121
### Active-Only Snapshots
67
122
68
123
When you're only interested in active components (fewer objects, less memory):
@@ -342,6 +397,8 @@ The filter method creates a new snapshot containing only objects that match your
342
397
>>> server_snapshot = create_snapshot(server)
343
398
```
344
399
400
+
> **KEY FEATURE:** The `filter()` method is one of the most powerful snapshot features. It lets you query your tmux hierarchy using any custom logic and returns a new snapshot containing only matching objects while maintaining their relationships.
0 commit comments