Drain ``master_fd`` non-blocking and write the batch to stdout. Returns ``False`` if the child closed (EIO or EOF), else ``True``. The drain does NOT paint the footer. Painting between child writes regularly lands inside an Ink frame burst — between two of the child
(self, master_fd: int)
| 194 | self._write(self._build_footer_bytes(rows, cols)) |
| 195 | |
| 196 | def _drain(self, master_fd: int) -> bool: |
| 197 | """Drain ``master_fd`` non-blocking and write the batch to stdout. |
| 198 | |
| 199 | Returns ``False`` if the child closed (EIO or EOF), else ``True``. |
| 200 | |
| 201 | The drain does NOT paint the footer. Painting between child writes |
| 202 | regularly lands inside an Ink frame burst — between two of the |
| 203 | child's small write() calls, where the next bytes would have been |
| 204 | the continuation of an unfinished CSI — and the paint's own ESC |
| 205 | resets the terminal's parser. The footer thread paints separately, |
| 206 | debounced on ``_FOOTER_QUIET_THRESHOLD_S`` of child silence so it |
| 207 | only ever falls in a gap between bursts. |
| 208 | """ |
| 209 | chunks: list[bytes] = [] |
| 210 | eof = False |
| 211 | while True: |
| 212 | try: |
| 213 | data = os.read(master_fd, 65536) |
| 214 | except BlockingIOError: |
| 215 | break |
| 216 | except OSError as e: |
| 217 | if e.errno == errno.EIO: |
| 218 | eof = True |
| 219 | break |
| 220 | raise |
| 221 | if not data: |
| 222 | eof = True |
| 223 | break |
| 224 | chunks.append(data) |
| 225 | if chunks: |
| 226 | batch = b"".join(chunks) |
| 227 | with self._out_lock: |
| 228 | _writeall(sys.stdout.fileno(), batch) |
| 229 | # Stamp inside the lock so the footer thread, if it |
| 230 | # acquires the lock next, observes a fresh timestamp on |
| 231 | # its inside-lock re-check and skips painting. |
| 232 | self._last_activity_ts = time.monotonic() |
| 233 | return not eof |
| 234 | |
| 235 | def _maybe_paint_footer(self) -> bool: |
| 236 | """Paint the footer if the child has been quiet long enough. |