1313 TypeVar ,
1414)
1515
16- from libtmux .exc import LibTmuxException
17- from libtmux .test .retry import WaitTimeout , retry_until
16+ from libtmux .exc import LibTmuxException , WaitTimeout
17+ from libtmux .test .retry import retry_until
1818
1919if t .TYPE_CHECKING :
2020 from libtmux .pane import Pane
@@ -62,7 +62,7 @@ def __init__(self, pane: Pane, timeout: float = 2.0) -> None:
6262 def _check_content (
6363 self ,
6464 predicate : t .Callable [[str ], bool ],
65- result : WaitResult ,
65+ result : WaitResult [ str ] ,
6666 ) -> bool :
6767 """Check pane content against predicate.
6868
@@ -88,7 +88,8 @@ def _check_content(
8888 if predicate (content ):
8989 result .value = content
9090 return True
91- return False
91+ else :
92+ return False
9293 except Exception as e :
9394 error = WaiterContentError ("Error capturing pane content" )
9495 error .__cause__ = e
@@ -100,16 +101,16 @@ def wait_for_content(
100101 timeout_seconds : float | None = None ,
101102 interval_seconds : float | None = None ,
102103 error_message : str | None = None ,
103- ) -> WaitResult :
104+ ) -> WaitResult [ str ] :
104105 """Wait for content in the pane to match a predicate."""
105- result = WaitResult (success = False , value = None , error = None )
106+ result = WaitResult [ str ] (success = False , value = None , error = None )
106107 try :
107108 # Give the shell a moment to be ready
108109 time .sleep (0.1 )
109110 success = retry_until (
110111 lambda : self ._check_content (predicate , result ),
111112 seconds = timeout_seconds or self .timeout ,
112- interval = interval_seconds ,
113+ interval = interval_seconds or 0.05 ,
113114 raises = True ,
114115 )
115116 result .success = success
@@ -124,11 +125,7 @@ def wait_for_content(
124125 result .error = e
125126 result .success = False
126127 except Exception as e :
127- if isinstance (e , (WaiterTimeoutError , WaiterContentError )):
128- result .error = e
129- else :
130- result .error = WaiterContentError ("Error capturing pane content" )
131- result .error .__cause__ = e
128+ result .error = WaiterTimeoutError (error_message or str (e ))
132129 result .success = False
133130 return result
134131
@@ -137,7 +134,7 @@ def wait_for_prompt(
137134 prompt : str ,
138135 timeout_seconds : float | None = None ,
139136 error_message : str | None = None ,
140- ) -> WaitResult :
137+ ) -> WaitResult [ str ] :
141138 """Wait for a specific prompt to appear in the pane."""
142139 return self .wait_for_content (
143140 lambda content : prompt in content and len (content .strip ()) > 0 ,
@@ -149,11 +146,15 @@ def wait_for_text(
149146 self ,
150147 text : str ,
151148 timeout_seconds : float | None = None ,
149+ interval_seconds : float | None = None ,
152150 error_message : str | None = None ,
153- ) -> WaitResult :
154- """Wait for specific text to appear in the pane."""
151+ ) -> WaitResult [str ]:
152+ """Wait for text to appear in the pane."""
153+ if error_message is None :
154+ error_message = f"Text '{ text } ' not found in pane"
155155 return self .wait_for_content (
156156 lambda content : text in content ,
157157 timeout_seconds = timeout_seconds ,
158- error_message = error_message or f"Text '{ text } ' not found in pane" ,
158+ interval_seconds = interval_seconds ,
159+ error_message = error_message ,
159160 )
0 commit comments