@@ -131,6 +131,75 @@ True
131131True
132132```
133133
134+ ### Capture with ANSI escape sequences
135+
136+ Capture colored output with escape sequences preserved using ` escape_sequences=True ` :
137+
138+ ``` python
139+ >> > import time
140+
141+ >> > pane.send_keys(' printf "\\ 033[31mRED\\ 033[0m \\ 033[32mGREEN\\ 033[0m"' )
142+ >> > time.sleep(0.1 )
143+
144+ >> > # Capture with ANSI codes stripped (default)
145+ >> > output = pane.capture_pane()
146+ >> > ' RED' in ' \\ n' .join(output)
147+ True
148+
149+ >> > # Capture with ANSI escape sequences preserved
150+ >> > colored_output = pane.capture_pane(escape_sequences = True )
151+ >> > isinstance (colored_output, list )
152+ True
153+ ```
154+
155+ ### Join wrapped lines
156+
157+ Long lines that wrap in the terminal can be joined back together:
158+
159+ ``` python
160+ >> > import time
161+
162+ >> > # Send a very long line that will wrap
163+ >> > pane.send_keys(' echo "' + ' x' * 200 + ' "' )
164+ >> > time.sleep(0.1 )
165+
166+ >> > # Capture with wrapped lines joined
167+ >> > output = pane.capture_pane(join_wrapped = True )
168+ >> > isinstance (output, list )
169+ True
170+ ```
171+
172+ ### Preserve trailing spaces
173+
174+ By default, trailing spaces are trimmed. Use ` preserve_trailing=True ` to keep them:
175+
176+ ``` python
177+ >> > import time
178+
179+ >> > pane.send_keys(' printf "text \\ n"' ) # 3 trailing spaces
180+ >> > time.sleep(0.1 )
181+
182+ >> > # Capture with trailing spaces preserved
183+ >> > output = pane.capture_pane(preserve_trailing = True )
184+ >> > isinstance (output, list )
185+ True
186+ ```
187+
188+ ### Capture flags summary
189+
190+ | Parameter | tmux Flag | Description |
191+ | -----------| -----------| -------------|
192+ | ` escape_sequences ` | ` -e ` | Include ANSI escape sequences (colors, attributes) |
193+ | ` escape_non_printable ` | ` -C ` | Escape non-printable chars as octal ` \xxx ` |
194+ | ` join_wrapped ` | ` -J ` | Join wrapped lines back together |
195+ | ` preserve_trailing ` | ` -N ` | Preserve trailing spaces at line ends |
196+ | ` trim_trailing ` | ` -T ` | Trim trailing empty positions (tmux 3.4+) |
197+
198+ :::{note}
199+ The ` trim_trailing ` parameter requires tmux 3.4+. If used with an older version,
200+ a warning is issued and the flag is ignored.
201+ :::
202+
134203## Waiting for Output
135204
136205A common pattern in automation is waiting for a command to complete.
0 commit comments