Skip to content

fix(prompts): eliminate spinner flicker via in-place overwrite and synchronized output - #646

Open
vazome wants to merge 1 commit into
bombshell-dev:mainfrom
vazome:fix/spinner-flicker
Open

vazome wants to merge 1 commit into
bombshell-dev:mainfrom
vazome:fix/spinner-flicker

Conversation

@vazome

@vazome vazome commented Nov 22, 2026

Copy link
Copy Markdown

What does this PR do?

Eliminates visible spinner and progress bar flickering on low-latency GPU terminals (reproduced on macOS Ghostty as well as Linux Ptyxis/VTE in #613).

Root cause

On every 80ms tick, spinner() previously cleared the entire region with erase.down() (CSI J) and then wrote the new frame across 3–4 separate output.write() calls (cursor.up, cursor.to(0), erase.down(), then the frame). Terminals that paint promptly on PTY reads (like Ghostty and Ptyxis) render the intermediate blank state between erase.down() and the new frame, causing visible strobing. Batching the old ESC[1G + ESC[J + text sequence alone still passes through a blank erased state.

Fix

  • Overwrite in place before clearing: Write each rendered line followed by erase.lineEnd (CSI K) instead of calling erase.down() before drawing. Only append erase.down() after drawing when a multi-line frame shrinks to fewer rows.
  • Single output.write() per frame (both on ticks and on _stop()).
  • DEC Mode 2026 synchronized output (\x1b[?2026h … \x1b[?2026l) around interactive frame writes (skipped in CI mode). Supported natively by Ghostty, VTE/Ptyxis, Kitty, WezTerm, iTerm2, Alacritty, and xterm.js 6+; ignored by terminals that do not implement private mode 2026.

Because progress() delegates to spinner(), this fixes both spinner() and progress().

Closes #613

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • pnpm test passes (or targeted tests for my change) — spinner.test.ts, progress-bar.test.ts, spinner-accessible.test.ts (118/118), pnpm types, and pnpm run build pass
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

@changeset-bot

changeset-bot Bot commented Nov 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d5b9ae7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clack/prompts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vazome
vazome marked this pull request as ready for review November 22, 2026 16:20
@43081j

43081j commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

this is a pretty big rewrite of something we want to get rid of (see #479 ).

sadly that PR is blocked because of Windows (the spinner in main has a bug on windows today which that PR fixes, but that reintroduces a different windows bug...)

i think i'd rather see that land than touching this logic. let's see what @dreyfus92 thinks

@dreyfus92 dreyfus92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hey @vazome, thanks for digging into this! i'm with james on not landing it as is though. i tested it and found a few things:

  • when a wrapped row exactly fills the terminal, the ESC[K after it can eat the row's last character (saw it in gnu screen)
  • it conflicts with #645, which landed today
  • no windows testing yet

@43081j since #479 doesn't have a date, i tried a tiny version on main. same clear and draw as today, just written once and wrapped in synchronized output. it's about 20 lines in spinner.ts and gets us one write per frame. would you be ok landing something that small first, or still rather wait?

also the start() reset in here fixes a real bug on main, so that part is worth keeping either way.

@43081j

43081j commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

really we should just get 479 finished as its been sat there for far too long.

it is now blocked because of the accessible changes, though. we would need to add support for that stuff to Prompt so the new spinner can enter some kind of append-only mode.

i think we should close this and do the following:

  1. whatever the fix is you mentioned, do it in its own PR (start() reset)
  2. prep Prompt for accessible mode
  3. catch the spinner branch up from main and merge it with whichever windows bug is the least bad

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] Progress bar visibly flickers in Ptyxis 50.1 but not in Zed terminal

3 participants