Skip to content

Commit 3e31827

Browse files
committed
docs(api) Add snapshot
1 parent b4c7620 commit 3e31827

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

docs/api/snapshot.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
(snapshot)=
2+
3+
# Snapshots
4+
5+
The snapshot module provides functionality for capturing and analyzing the state of tmux panes.
6+
7+
## Core Classes
8+
9+
```{eval-rst}
10+
.. autoclass:: libtmux.snapshot.PaneSnapshot
11+
:members:
12+
:inherited-members:
13+
:show-inheritance:
14+
:member-order: bysource
15+
16+
.. autoclass:: libtmux.snapshot.PaneRecording
17+
:members:
18+
:inherited-members:
19+
:show-inheritance:
20+
:member-order: bysource
21+
```
22+
23+
## Output Adapters
24+
25+
```{eval-rst}
26+
.. autoclass:: libtmux.snapshot.SnapshotOutputAdapter
27+
:members:
28+
:inherited-members:
29+
:show-inheritance:
30+
:member-order: bysource
31+
32+
.. autoclass:: libtmux.snapshot.TerminalOutputAdapter
33+
:members:
34+
:inherited-members:
35+
:show-inheritance:
36+
:member-order: bysource
37+
38+
.. autoclass:: libtmux.snapshot.CLIOutputAdapter
39+
:members:
40+
:inherited-members:
41+
:show-inheritance:
42+
:member-order: bysource
43+
44+
.. autoclass:: libtmux.snapshot.PytestDiffAdapter
45+
:members:
46+
:inherited-members:
47+
:show-inheritance:
48+
:member-order: bysource
49+
50+
.. autoclass:: libtmux.snapshot.SyrupySnapshotAdapter
51+
:members:
52+
:inherited-members:
53+
:show-inheritance:
54+
:member-order: bysource
55+
```
56+
57+
## Examples
58+
59+
### Basic Snapshot
60+
61+
```python
62+
>>> pane = session.active_window.active_pane
63+
>>> snapshot = pane.snapshot()
64+
>>> print(snapshot.content_str)
65+
$ echo "Hello World"
66+
Hello World
67+
$
68+
```
69+
70+
### Recording Activity
71+
72+
```python
73+
>>> recording = pane.record()
74+
>>> recording.add_snapshot(pane)
75+
>>> pane.send_keys("echo 'Hello'")
76+
>>> recording.add_snapshot(pane)
77+
>>> print(recording.latest.content_str)
78+
$ echo 'Hello'
79+
Hello
80+
$
81+
```
82+
83+
### Using Output Adapters
84+
85+
```python
86+
>>> from libtmux.snapshot import TerminalOutputAdapter
87+
>>> print(snapshot.format(TerminalOutputAdapter()))
88+
=== Pane Snapshot ===
89+
Pane: %1
90+
Window: @1
91+
Session: $1
92+
Server: default
93+
Timestamp: 2024-01-01T12:00:00Z
94+
=== Content ===
95+
$ echo "Hello World"
96+
Hello World
97+
$
98+
```
99+
100+
### Custom Adapter
101+
102+
```python
103+
>>> from libtmux.snapshot import SnapshotOutputAdapter
104+
>>> class MyAdapter(SnapshotOutputAdapter):
105+
... def format(self, snapshot):
106+
... return f"Content: {snapshot.content_str}"
107+
>>> print(snapshot.format(MyAdapter()))
108+
Content: $ echo "Hello World"
109+
Hello World
110+
$
111+
```

0 commit comments

Comments
 (0)