Skip to content

Rebuild visible terminal lines after resize#234

Open
thewsdearman wants to merge 3 commits into
connectbot:mainfrom
thewsdearman:fix-resize-screen-rebuild
Open

Rebuild visible terminal lines after resize#234
thewsdearman wants to merge 3 commits into
connectbot:mainfrom
thewsdearman:fix-resize-screen-rebuild

Conversation

@thewsdearman

Copy link
Copy Markdown

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:

  • Rebuild every visible terminal line from the native buffer
  • Publish a fresh terminal snapshot
  • Notify listeners of the updated dimensions

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:

  • Samsung Galaxy Tab A9+ rotation
  • Samsung Galaxy Fold 5 inner display rotation
  • Active SSH session preserved
  • Keyboard interaction preserved
  • Native Android long-press paste preserved
  • 500-line multiline paste preserved

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via updateLine().
  • Immediately publishes a new TerminalSnapshot after 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.

Comment on lines +413 to +424
// 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
@thewsdearman

Copy link
Copy Markdown
Author

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.

@thewsdearman

Copy link
Copy Markdown
Author

Good catch. I updated the resize handling so it no longer rebuilds and publishes the terminal snapshot directly inside resize().

The resize path now:

  • resizes currentLines under damageLock so row indexing remains safe after dimension changes
  • queues a full-screen DamageRegion with preserveSegments = false
  • routes the repaint through requestProcessPendingUpdatesLocked()
  • leaves snapshot rebuild/publish on the normal scheduled update path

Validation completed:

  • spotlessKotlinCheck compileDebugKotlin compileReleaseKotlin passed
  • :lib:assembleRelease passed
  • tested the rebuilt AAR inside DearmanSSH
  • DearmanSSH assembleDebug passed
  • DearmanSSH installDebug passed
  • manual Fold rotation test passed portrait → landscape → portrait with an active SSH session

Commit pushed: ffc85d5 Fix resize snapshot rebuild scheduling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants