Skip to content

fix: reset cursor to column 0 after inquirer prompts on Windows#278

Merged
rhuanbarreto merged 3 commits into
mainfrom
fix/inquirer-cursor-position-windows
May 8, 2026
Merged

fix: reset cursor to column 0 after inquirer prompts on Windows#278
rhuanbarreto merged 3 commits into
mainfrom
fix/inquirer-cursor-position-windows

Conversation

@rhuanbarreto

@rhuanbarreto rhuanbarreto commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • On Windows terminals, after any inquirer prompt completes, the cursor stays at the column where the rendered answer text ended. If the line wraps, subsequent output lines start at the wrong horizontal offset — producing garbled output.
  • Root cause: Inquirer's shared onClose path (prompt.js:210-212) writes cursorShow + rl.close() but never resets the cursor column to 0. This affects ALL prompt types (checkbox, list, input, confirm).
  • Fix: Call cursorTo(process.stdout, 0) from node:readline after every inquirer.prompt() call, guarded by process.stdout.isTTY.

Files fixed

File Prompts Types
src/helpers/editor-detect.ts 2 checkbox, list
src/helpers/login-flow.ts 4 input, list, input, confirm
src/commands/init.ts 1 confirm
src/commands/adr/create.ts 1 list + 2× input (single prompt call)

Total: 8 prompt sites across 4 files, covering every inquirer.prompt() call in the codebase.

Test plan

  • bun run validate passes (lint, typecheck, format, 729 tests, 23/23 ADR checks, build)
  • 4 new tests: promptEditorSelection and promptSingleEditorSelection verify cursorTo(stdout, 0) is called (TTY) / not called (non-TTY)
  • Manual: run archgate plugin install on Windows — output lines should start at column 0
  • Manual: run archgate login on Windows — signup prompts should not garble subsequent output
  • Manual: run archgate adr create on Windows — output after interactive prompts is clean

On Windows terminals, inquirer leaves the cursor at the end of the
rendered answer text after a prompt completes. When the answer wraps
across multiple lines (e.g. checkbox with several editors selected),
subsequent console output starts at the wrong horizontal offset because
\n moves the cursor down without resetting to column 0.

Fix by calling cursorTo(process.stdout, 0) from node:readline after
each prompt returns, guarded by process.stdout.isTTY. Applied to both
promptEditorSelection() and promptSingleEditorSelection() in
src/helpers/editor-detect.ts.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
Verify that promptEditorSelection() and promptSingleEditorSelection()
call cursorTo(process.stdout, 0) when stdout is a TTY, and skip the
call when stdout is piped. Uses mock.module to intercept node:readline
and inquirer for isolated, non-interactive testing.

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 7, 2026

Copy link
Copy Markdown

Deploying archgate-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: 482a0b4
Status: ✅  Deploy successful!
Preview URL: https://33fdd5ba.archgate-cli.pages.dev
Branch Preview URL: https://fix-inquirer-cursor-position.archgate-cli.pages.dev

View logs

Inquirer's shared close path (prompt.js onClose) writes cursorShow +
rl.close() without resetting the cursor column. On Windows terminals
this causes garbled output after ANY prompt whose rendered answer wraps
past the terminal width.

Apply the same cursorTo(process.stdout, 0) fix to:
- login-flow.ts (4 prompts: email, editor, use case, confirm)
- init.ts (1 prompt: want plugin confirm)
- adr/create.ts (1 prompt: domain/title/files)

Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
@rhuanbarreto rhuanbarreto merged commit e390c47 into main May 8, 2026
11 of 15 checks passed
@rhuanbarreto rhuanbarreto deleted the fix/inquirer-cursor-position-windows branch May 8, 2026 07:09
@archgatebot archgatebot Bot mentioned this pull request May 8, 2026
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.

1 participant