Skip to content

Fix terminal prompt redraws to always start on a new line #78

Closed

Description

@kbuffardi

Problem

The terminal can display redundant prompts on the same line, for example browser.cpp:~$ browser.cpp:~$ . This has been observed when the clear terminal button or shortcut redraws the prompt after one is already visible, and the same class of bug can occur anywhere a prompt is restored without first ensuring the cursor is at the start of a fresh line.

Desired behavior

Every newly displayed shell prompt should begin on its own terminal line. Prompt redraws should never concatenate with an existing prompt, partially typed command, compiler/runtime output, or informational message.

Proposed solution

Centralize prompt rendering in src/ui/terminal.js behind a newline-aware helper. The helper should track whether the terminal cursor/output is already at a fresh prompt position and insert CRLF before writing a new prompt whenever the previous terminal write did not end on a fresh line. Then route prompt-producing paths such as clearTerminal(), resetTerminalSession(), showInitialPrompt(), onCompileResult(), onRunResult(), command completion, idle Ctrl+C, and Ctrl+L through the same invariant.

Acceptance criteria

  • Pressing the clear terminal button after the prompt is visible redraws exactly one prompt, and that prompt starts on a new line.
  • Pressing Ctrl+K after the prompt is visible has the same behavior as the clear button.
  • The terminal never renders adjacent prompt text like browser.cpp:~$ browser.cpp:~$ .
  • Existing startup behavior remains intact: the initial prompt is not shown before compiler readiness and is only written once.
  • Existing command, compile, run, stdin, Ctrl+C, Ctrl+L, and workspace reset prompt flows continue to restore prompts correctly.
  • Node E2E tests cover prompt newline behavior and the full E2E suite, lint, and build pass.

Activity

  1. kbuffardi commented on Aug 22, 2026

    @kbuffardi
    OwnerAuthor

    Plan revision — approved requirements

    @kbuffardi confirmed: “yes to all questions. To 4, the prompt should sit at the top-left with no blank line.”

    Decisions

    • Clear button / Ctrl+K discards partially typed input and shows one fresh empty prompt.
    • Ctrl+L preserves partially typed input after redraw.
    • A prompt following compiler or program output that lacks a trailing newline must begin on the following line.
    • After any clear operation, the prompt appears at the cleared screen’s top-left with no leading blank line.
    • Shell clear remains in command history but is not visible after the terminal is cleared.

    Revised implementation plan

    1. Inventory every prompt-producing path in src/ui/terminal.js and classify whether it preserves or discards typed input.
    2. Replace the raw prompt write with one prompt-rendering path that allows a prompt only on a prompt-safe line. Track whether visible output ended with CRLF through a small shared write wrapper, or use an equivalent testable state mechanism.
    3. Add one clear-screen helper for clearTerminal(), Ctrl+L, shell clear, and resetTerminalSession(); it explicitly resets line/prompt state after term.clear().
    4. Route all prompt redraws through the helper without scattering manual CRLF writes. Include startup, command completion, compile/run completion, stop/error paths, and toolbar clear.
    5. Add focused Node E2E coverage for clearTerminal/Ctrl+K, Ctrl+L with and without input, shell clear, output without trailing newline, initial prompt idempotence, and compiler-readiness ordering. The assertions should detect visible adjacent prompts rather than only count writes.
    6. Validate with npm run test:e2e, npm run lint, and npm run build.

    Scope: reuse the existing xterm and terminal-test harnesses; do not add dependencies.

  2. kbuffardi commented on Aug 22, 2026

    @kbuffardi
    OwnerAuthor

    Implementation is ready for review in PR #79: #79

    Delivered the approved behavior: clear/Ctrl+K discards typed input and redraws one prompt at the top-left; Ctrl+L preserves typed input; and restored prompts follow newline-less output on a new line. The patch version is now 0.4.7.

    Validated with npm run lint, npm run test:e2e (179 passing), npm run build, and npm run version:check.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions