Optimize screenshot updates using pyte dirty tracking

- get_screen_state() now returns has_changes flag indicating if screen changed
- pyte's dirty set tracks which rows have been modified since last read
- Screenshot handler returns cached SVG immediately when no changes detected
- Removed _screenshot_last_rendered_activity tracking (replaced by dirty flag)
- Added test for dirty flag behavior

Bump version to 0.1.16
This commit is contained in:
GitHub Copilot
2026-01-24 11:27:33 +00:00
parent 8ae3f77f23
commit ff8f5efabd
5 changed files with 54 additions and 34 deletions
+11 -4
View File
@@ -140,16 +140,23 @@ class TerminalSession(Session):
async with self._screen_lock:
return [line.rstrip() for line in self._screen.display]
async def get_screen_state(self) -> tuple[int, int, list]:
async def get_screen_state(self) -> tuple[int, int, list, bool]:
"""Get the current screen state including dimensions and character buffer.
Returns:
Tuple of (width, height, buffer) where buffer is a list of rows,
each row containing character data with styling attributes.
Tuple of (width, height, buffer, has_changes) where:
- width: screen width in columns
- height: screen height in rows
- buffer: list of rows, each containing character data with styling
- has_changes: True if screen has changed since last call
"""
async with self._screen_lock:
width = self._screen.columns
height = self._screen.lines
# Check if any rows are dirty (changed since last clear)
has_changes = len(self._screen.dirty) > 0
# Clear dirty set after checking
self._screen.dirty.clear()
# Copy the buffer data to avoid holding the lock
buffer = []
for row in range(height):
@@ -166,7 +173,7 @@ class TerminalSession(Session):
"reverse": char.reverse,
})
buffer.append(row_data)
return (width, height, buffer)
return (width, height, buffer, has_changes)
def update_connector(self, connector: SessionConnector) -> None:
"""Update the connector for reconnection without restarting the session."""