Skip to content

Stop stacking prompts when the terminal is resized - #1069

Open
lenitain wants to merge 2 commits into
HalFrgrd:masterfrom
lenitain:fix/resize-prompt-leak
Open

lenitain wants to merge 2 commits into
HalFrgrd:masterfrom
lenitain:fix/resize-prompt-leak

Conversation

@lenitain

@lenitain lenitain commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1068.

Problem

Resizing the terminal while the prompt is on screen leaves the old prompt behind and draws a new one below it, so repeated resizes (toggling a column width with mod+f / mod+a in niri, or just dragging the window edge) fill the screen with stacked prompts. Reproducible in foot with a 4-character prompt (/tmp), so it is not about prompt wrapping.

Root cause

On TerminaEvent::WindowResized the handler erases the inline viewport with Cursor::Up(rows_up) + Edit::DeleteLine(rows_up + 1) + terminal.clear(), then redraws. rows_up is computed from the rows Flyline itself drew.

foot implements DL as a scroll of the cursor-to-bottom region (csi.c, case 'M' -> term_scroll_partial()), which advances the grid ring buffer's offset (grid->offset += rows, terminal.c) while the visible screen stays unchanged. The next reflow (grid_resize_and_reflow(), grid.c) converts the cursor to an absolute row (cursor.row += grid->offset), reflows, then re-anchors the grid to the reflowed rows. The cursor's screen row becomes old_screen_row + old_offset - new_offset; in the observed case new_offset is 0, so it ends up old_offset rows below the prompt.

Cursor::Up(rows_up) then starts from that shifted cursor, so the erase targets the rows below the old prompt: the old block survives, a new one is drawn below it, and the next resize repeats the cycle.

Captured stream for one resize with a 2-row prompt.

ESC[1A ESC[G ESC[2M ESC[G ESC[0J
ESC[6n -> ESC[3;1R    # cursor is on row 3, but the block starts on row 1

Fix

DeleteLine is only needed to reset a multiplexer's "line is wrapped" bookkeeping (zellij combines lines on widen, #909), and multiplexers handle the delete in their own grid. On a direct terminal terminal.clear() already sends ED(0) from the same position, which blanks the block. So only send DL when term_info::multiplexer() is Some(_).

Why this isn't foot-specific

The failure requires the combination of three properties: DL advances a global grid offset, reflow uses that offset to convert the cursor, and the deleted rows remain in the buffer and can be reflowed back. Foot has all three. Alacritty's DL also scrolls the region (rows can go into history), but its reflow tracks an explicit cursor line and keeps the viewport pinned to the bottom, so the cursor stays aligned with the prompt and the old rows are not pulled back into view. Kitty and Ghostty actually move/clear the deleted rows and honor the OSC 133 prompt-redraw markers, so there is no stale block and no offset applied during reflow. They are not handling DL differently on purpose; they simply never enter the state where a hidden offset is applied to the cursor during reflow. The fix does not detect foot: it removes DL from the direct-terminal path, so any terminal with that combination is covered, while the multiplexer path keeps the zellij workaround.

Testing

  • New tests/resize_no_delete_line.py: drives Flyline in a PTY, resizes, and asserts that a direct terminal gets no CSI M while a ZELLIJ session still does. It waits for the post-resize CPR query, so it cannot pass without exercising the resize path. The test is wired into docker/bash_integration_test.Dockerfile and runs on every Bash version in CI. It fails on 1.10.0 and passes with the patch.
  • All CI checks pass, including Code Quality, the Ubuntu 16.04 build, and the Bash 3.2.57 / 4.4-rc1 / 4.4.18 / 5.0 / 5.3 integration tests.
  • In a manual foot test, 3 narrow/wide cycles used to leave 6 extra prompt blocks; after the patch only the prompt remains. Typing and command output keep working, and output above the prompt is not cleared.
  • In a real zellij session, resizing a wrapped command line does not regress the More resize improvements #909 behavior.
  • I also smoke-tested Alacritty, Kitty, and Ghostty, and resizing behaves correctly there.
  • cargo test --lib (908 passed), cargo fmt --all -- --check.

Notes

  • Behaviour is unchanged inside multiplexers; the DL workaround for zellij stays.
  • Code Quality CI passes on the project's Rust 1.94.1 toolchain. Local 1.100 reports pre-existing needless_range_loop lints in untouched files.

Fixes HalFrgrd#1068

The resize handler erased its inline viewport with DeleteLine. foot
implements DL as a rotation of its grid ring buffer: the screen looks
unchanged, but the terminal's viewport offset moves, and the next reflow
then leaves the cursor rows below the reflowed prompt. Cursor::Up is
computed from our own drawn buffer, so it lands on the wrong row and the
old prompt is never erased - every resize leaves another copy on screen
and draws a fresh one below it.

Only multiplexers need the DL: they keep their own "line is wrapped"
bookkeeping across redraws (zellij combines lines on widen, see HalFrgrd#909) and
handle the delete in their grid. On a direct terminal terminal.clear()'s
ED already blanks the block, so skip the scroll there.

tests/resize_no_delete_line.py drives flyline in a PTY and checks that a
direct terminal gets no CSI M on resize while a ZELLIJ session still does.
@lenitain
lenitain force-pushed the fix/resize-prompt-leak branch from 7495943 to 9e13d59 Compare November 17, 2026 05:09
Wire tests/resize_no_delete_line.py into the Bash integration Dockerfile and wait for the post-resize CPR query before checking the escape stream. This prevents the direct-terminal branch from passing when no resize was handled, and filters terminal and multiplexer environment variables so the test observes the intended foot and zellij paths.

Also tighten the resize comment in src/app/mod.rs.
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.

[BUG]: Every window resize leaves another prompt behind in foot

1 participant