Skip to content

Commit 748173b

Browse files
committed
docs(CHANGES): Add visual examples for capture_frame()
why: Show actual frame output to help users understand the feature. what: - Add basic usage example with rendered ASCII frame output - Add multiline output example demonstrating printf capture - Add truncation example showing long lines clipped to frame width - Reorganize into sections: Basic, Multiline, Truncation, Snapshot testing
1 parent a9e0160 commit 748173b

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

CHANGES

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,56 @@ New {meth}`~libtmux.pane.Pane.capture_frame` method that wraps
103103
{meth}`~libtmux.pane.Pane.capture_pane` and returns a
104104
{class}`~libtmux.textframe.TextFrame` for visualization and snapshot testing.
105105

106+
**Basic usage:**
107+
108+
```python
109+
pane.send_keys('echo "Hello, TextFrame!"', enter=True)
110+
frame = pane.capture_frame(content_width=30, content_height=5)
111+
print(frame.render())
112+
# +------------------------------+
113+
# |$ echo "Hello, TextFrame!" |
114+
# |Hello, TextFrame! |
115+
# |$ |
116+
# | |
117+
# | |
118+
# +------------------------------+
119+
```
120+
121+
**Multiline output:**
122+
123+
```python
124+
pane.send_keys('printf "a\\nb\\nc\\n"', enter=True)
125+
frame = pane.capture_frame(content_width=20, content_height=6)
126+
print(frame.render())
127+
# +--------------------+
128+
# |$ printf "a\nb\nc\n"|
129+
# |a |
130+
# |b |
131+
# |c |
132+
# |$ |
133+
# | |
134+
# +--------------------+
135+
```
136+
137+
**Truncation (long lines clipped to frame width):**
138+
139+
```python
140+
pane.send_keys('echo "' + "x" * 50 + '"', enter=True)
141+
frame = pane.capture_frame(content_width=15, content_height=4)
142+
print(frame.render())
143+
# +---------------+
144+
# |$ echo "xxxxxxx|
145+
# |xxxxxxxxxxxxxxx|
146+
# |$ |
147+
# | |
148+
# +---------------+
149+
```
150+
151+
**Snapshot testing:**
152+
106153
```python
107154
def test_cli_output(pane, textframe_snapshot):
108155
pane.send_keys("echo 'Hello'", enter=True)
109-
110-
# Wait for output, then capture as frame
111156
frame = pane.capture_frame(content_width=40, content_height=10)
112157
assert frame == textframe_snapshot
113158
```

0 commit comments

Comments
 (0)