File tree Expand file tree Collapse file tree
src/runloop_api_client/sdk Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,16 +50,30 @@ def failed(self) -> bool:
5050
5151 # TODO: add pagination support once we have it in the API
5252 async def stdout (self , num_lines : Optional [int ] = None ) -> str :
53- if not num_lines or num_lines <= 0 or not self ._result .stdout :
54- return ""
55- return self ._result .stdout [- num_lines :]
53+ text = self ._result .stdout or ""
54+ return _tail_lines (text , num_lines )
5655
5756 # TODO: add pagination support once we have it in the API
5857 async def stderr (self , num_lines : Optional [int ] = None ) -> str :
59- if not num_lines or num_lines <= 0 or not self ._result .stderr :
60- return ""
61- return self ._result .stderr [- num_lines :]
58+ text = self ._result .stderr or ""
59+ return _tail_lines (text , num_lines )
6260
6361 @property
6462 def raw (self ) -> DevboxAsyncExecutionDetailView :
6563 return self ._result
64+
65+
66+ def _tail_lines (text : str , num_lines : Optional [int ]) -> str :
67+ if not text :
68+ return ""
69+ if num_lines is None or num_lines <= 0 :
70+ return text
71+
72+ lines = text .splitlines ()
73+ if not lines :
74+ return text
75+
76+ clipped = "\n " .join (lines [- num_lines :])
77+ if text .endswith ("\n " ):
78+ clipped += "\n "
79+ return clipped
Original file line number Diff line number Diff line change @@ -59,18 +59,32 @@ def failed(self) -> bool:
5959 # TODO: add pagination support once we have it in the API
6060 def stdout (self , num_lines : Optional [int ] = None ) -> str :
6161 """Return captured standard output."""
62- if not num_lines or num_lines <= 0 or not self ._result .stdout :
63- return ""
64- return self ._result .stdout [- num_lines :]
62+ text = self ._result .stdout or ""
63+ return _tail_lines (text , num_lines )
6564
6665 # TODO: add pagination support once we have it in the API
6766 def stderr (self , num_lines : Optional [int ] = None ) -> str :
6867 """Return captured standard error."""
69- if not num_lines or num_lines <= 0 or not self ._result .stderr :
70- return ""
71- return self ._result .stderr [- num_lines :]
68+ text = self ._result .stderr or ""
69+ return _tail_lines (text , num_lines )
7270
7371 @property
7472 def raw (self ) -> DevboxAsyncExecutionDetailView :
7573 """Access the underlying API response."""
7674 return self ._result
75+
76+
77+ def _tail_lines (text : str , num_lines : Optional [int ]) -> str :
78+ if not text :
79+ return ""
80+ if num_lines is None or num_lines <= 0 :
81+ return text
82+
83+ lines = text .splitlines ()
84+ if not lines :
85+ return text
86+
87+ clipped = "\n " .join (lines [- num_lines :])
88+ if text .endswith ("\n " ):
89+ clipped += "\n "
90+ return clipped
You can’t perform that action at this time.
0 commit comments