Skip to content

feat: add PROMPT2 support for multi-line query continuation#577

Open
buck-openart wants to merge 1 commit into
xo:mainfrom
buck-openart:prompt2-support
Open

feat: add PROMPT2 support for multi-line query continuation#577
buck-openart wants to merge 1 commit into
xo:mainfrom
buck-openart:prompt2-support

Conversation

@buck-openart

@buck-openart buck-openart commented May 21, 2026

Copy link
Copy Markdown

Summary

Implements PROMPT2, the continuation prompt shown on lines 2+ of a multi-line statement — matching psql behaviour.

  • Wires up PROMPT2: moves prompt selection into the f() readline reader closure so it fires before each individual readline call. The previous approach set the prompt once per statement in Run(), but stmt.Next() reads all continuation lines internally before returning, so PROMPT2 was never reached.
  • Default PROMPT2 is " " (two spaces) — unobtrusive, no visual noise. Users who prefer aligned whitespace can set \set PROMPT2 %w in ~/.usqlrc.
  • Implements %w: outputs whitespace matching the visual width of the last rendered PROMPT1, stripping ANSI escape sequences. Adds lastPromptWidth to Handler and a visualWidth() helper.
  • Registers PROMPT2 in env/vars.go defaults and env/list.go \? variables help output.

Test plan

  • Start usql against any database, paste a multi-line query — continuation lines show two spaces instead of the full prompt
  • \set PROMPT2 %w — continuation lines align with PROMPT1 width
  • \set PROMPT2 "" — no continuation prompt
  • \? variables lists PROMPT2

🤖 Generated with Claude Code

Implements PROMPT2, the continuation prompt shown on lines 2+ of a
multi-line statement — matching psql behaviour.

Changes:
- Move prompt selection into the f() readline reader closure so the
  prompt is updated before each individual readline call. The previous
  approach set it once per statement in Run(), but stmt.Next() reads
  all continuation lines internally before returning, so PROMPT2 was
  never seen by readline.
- Default PROMPT2 to "  " (two spaces). Users who prefer aligned
  whitespace can set PROMPT2 to %w in ~/.usqlrc.
- Implement %w: outputs whitespace matching the visual width of the
  last rendered PROMPT1, stripping ANSI escape sequences. Adds
  lastPromptWidth to Handler and a visualWidth() helper.
- Register PROMPT2 in env/vars.go defaults and env/list.go help output.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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