Skip to content

Commit 1ef0973

Browse files
committed
!squash pr description wip
1 parent eab61f7 commit 1ef0973

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

PR.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Enhanced Terminal Content Waiting Utility
2+
3+
## Overview
4+
5+
This PR introduces a significant enhancement to the terminal content waiting utility in libtmux. The changes include a more fluent API inspired by Playwright, improved error handling, type checking fixes, and the ability to wait for multiple content patterns.
6+
7+
## Key Features
8+
9+
### 1. Fluent API with Playwright-Inspired Design
10+
11+
```python
12+
# Before
13+
result = wait_for_pane_content(pane, "hello world", ContentMatchType.CONTAINS)
14+
15+
# After
16+
result = expect(pane).wait_for_text("hello world")
17+
18+
# With method chaining
19+
result = (
20+
expect(pane)
21+
.with_timeout(5.0)
22+
.without_raising()
23+
.wait_for_exact_text("completed successfully")
24+
)
25+
```
26+
27+
### 2. Multiple Pattern Support
28+
29+
```python
30+
# Wait for any of these patterns to appear
31+
result = wait_for_any_content(
32+
pane,
33+
["Success", "Error:", "timeout"],
34+
ContentMatchType.CONTAINS
35+
)
36+
if result.success:
37+
print(f"Pattern '{result.matched_content}' found at index {result.matched_pattern_index}")
38+
39+
# Wait for all patterns to appear
40+
result = wait_for_all_content(
41+
pane,
42+
["Database connected", "Server started"],
43+
ContentMatchType.CONTAINS
44+
)
45+
if result.success:
46+
for pattern in result.matched_content:
47+
print(f"Found pattern: {pattern}")
48+
```
49+
50+
### 3. Mixed Pattern Types
51+
52+
```python
53+
# Different match types in a single call
54+
result = wait_for_any_content(
55+
pane,
56+
[
57+
"exact match", # String for exact match
58+
"partial text", # String for contains match
59+
re.compile(r"\d+ items found"), # Regex pattern
60+
lambda lines: len(lines) > 10 # Predicate function
61+
],
62+
[
63+
ContentMatchType.EXACT,
64+
ContentMatchType.CONTAINS,
65+
ContentMatchType.REGEX,
66+
ContentMatchType.PREDICATE
67+
]
68+
)
69+
```
70+
71+
### 4. Performance and Debugging Improvements
72+
73+
- Added elapsed time tracking for timing information
74+
- Improved error messaging with detailed type checking
75+
- Fixed return type handling for `wait_for_all_content` to return a list of matched patterns
76+
77+
## Fixed Issues
78+
79+
- Resolved all type checking issues with proper type annotations
80+
- Fixed inconsistencies between `matched_line` and `match_line` attributes
81+
- Improved doctest examples to prevent execution failures
82+
- Resolved timeout message formatting
83+
84+
## Documentation
85+
86+
- Created comprehensive documentation in `docs/test-helpers/waiter.md`
87+
- Added examples for all usage patterns including the new fluent API
88+
- Updated API reference with accurate return types
89+
- Added detailed explanation of the `WaitResult` object properties
90+
91+
## Example Code
92+
93+
- Added example file in `tests/examples/test/test_waiter.py` demonstrating different ways to use the enhanced API
94+
- Ensured examples follow best practices and appropriate error handling
95+
96+
## Type Checking
97+
98+
- Improved type annotations for better IDE support and static type checking
99+
- Ensured full mypy compatibility with no type errors
100+
101+
## Testing
102+
103+
- All existing tests pass with no failures
104+
- Fixed test cases for `wait_for_any_content` and `wait_for_all_content`
105+
- Added comprehensive tests for the new fluent API methods
106+
- Made test_wait_until_ready.py more robust with fallback patterns and better error handling
107+
108+
## Recent Improvements
109+
110+
- Fixed linting and formatting issues throughout the waiter module
111+
- Improved error handling in wait functions with proper else blocks
112+
- Optimized code for readability and maintainability
113+
- Added conftest.py to register the example pytest marker
114+
- Made the shell prompt detection more robust using common prompt characters
115+
- Added and improved type annotations throughout the codebase
116+
117+
## Documentation
118+
119+
- Updated example code in test_wait_until_ready.py to use contextlib.suppress
120+
- Made all examples compatible with automated testing and documentation
121+
- Documentation is now fully synchronized with code examples via literalinclude directives

0 commit comments

Comments
 (0)