Rebuild visible terminal lines after resize#234
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to ensure the Compose-facing terminal state is fully repainted after a terminal resize (e.g., device rotation) by rebuilding visible rows from the native buffer and publishing a fresh snapshot.
Changes:
- Replaces
invalidateDisplay()-based redraw after resize with an explicit per-row rebuild viaupdateLine(). - Immediately publishes a new
TerminalSnapshotafter rebuilding visible rows. - Keeps the resize listener callback (
onResize) posted asynchronously.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // After native resize, rebuild every visible row from the native terminal buffer. | ||
| val fullDamageRegion = DamageRegion(0, newRows, 0, newCols) | ||
| for (row in 0 until newRows) { | ||
| updateLine( | ||
| row = row, | ||
| damageRegion = fullDamageRegion, | ||
| preserveMovedSegments = false, | ||
| ) | ||
| } | ||
|
|
||
| val newSnapshot = buildSnapshot() | ||
| _snapshot.value = newSnapshot |
|
Good catch. I agree the resize callback should not directly rebuild/publish terminal snapshots unless it is guaranteed to be on the same serialized terminal update path. I’m going to adjust this so resize requests a repaint through the same handler/executor path used for terminal updates, rather than rebuilding the snapshot directly inside the resize callback. That should preserve the rotation fix while avoiding stale snapshot/race conditions. |
|
Good catch. I updated the resize handling so it no longer rebuilds and publishes the terminal snapshot directly inside The resize path now:
Validation completed:
Commit pushed: |
Summary
Rebuild visible terminal lines after terminal resize.
Problem
After device rotation, the SSH session remains active and continues accepting input, but the visible terminal buffer may not be fully repainted. Commands execute successfully while output can appear blank or stale until another screen update occurs.
Solution
After the native terminal resize completes:
This keeps the Compose representation synchronized with the native terminal state after resize events.
Validation
Validated in a production Android SSH client using this library.
Verified:
One constrained case remains on the Galaxy Fold 5 outer display in landscape orientation, where command execution succeeds but output repaint may still be limited by the available viewport size.
This change substantially improves rotation behavior without affecting normal terminal operation.