Fix fullscreen trailing newline on initial render#856
Conversation
|
After further investigation, I found that removing the trailing newline to fix the fullscreen issue (#808) breaks existing functionality for non-fullscreen use cases. The core problem is that:
A proper fix would require adding a I'm closing this PR as the current approach doesn't work without breaking existing tests. If maintainers are interested, I can work on a more comprehensive solution with a |
|
I've updated this PR with a better approach. Previous approach: Unconditionally remove trailing newlines New approach: Add an opt-in // For fullscreen terminal apps (fixes #808)
render(<App />, { fullscreen: true });
// Default behavior unchanged (backwards compatible)
render(<App />);This way:
Let me know if you'd like any changes to the implementation! |
|
AI review:
|
|
We can actually avoid a AI idea:
This keeps API surface unchanged and fixes the cursor overshoot/trailing newline issues by making |
|
Updated per your feedback! I've removed the How it works:
log-update changes:
This keeps the API surface unchanged while fixing the cursor/newline issues automatically. |
|
AI review:
|
|
Updated to address all 5 review issues. Here's a summary of the changes: [P1] log-update appends trailing newline, negating fullscreen detection [P2] Incremental cursor math off-by-one [P2] [P2] Fullscreen detection with default rows on non-TTY [P3] |
|
|
Addressed both issues: P1 – Incremental no-trailing-newline path: Fixed three places in
P2 – Tests: Added 5 incremental no-trailing-newline tests:
|
Move trailing newline responsibility from log-update to ink.tsx so fullscreen mode (output fills terminal) can omit the newline that causes content to scroll up. Adds TTY guard so piped output always gets trailing newlines. Fixes #856. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fix three issues in createIncremental() that assumed a trailing newline: - Shrink path: only add +1 erase slot when previous output had trailing \n - Unchanged lines: skip cursorNextLine on last line without trailing \n - Changed lines: skip appending \n on last line without trailing \n Add 5 incremental no-trailing-newline tests covering trailing->no-trailing transition, no-trailing updates, shrink, grow, and cursor overshoot. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Add a
fullscreenrender option to fix the trailing newline issue in fullscreen terminal applications.The problem (issue #808):
In fullscreen mode, the trailing newline added on initial render caused the first line of the UI to be cut off.
Previous approach (broken):
Simply removing the trailing newline broke non-fullscreen use cases where the newline is needed so console output after Ink exits appears on a new line.
New approach (this PR):
Add a
fullscreenoption that users can enable when building fullscreen terminal applications:When
fullscreen: true:When
fullscreen: false(default):Related Issue
Fixes #808
Test plan
Changes
src/log-update.ts: Addfullscreenoption tocreateStandardandcreateIncrementalsrc/ink.tsx: Addfullscreento Options type and pass to logUpdate.createsrc/render.ts: Addfullscreento RenderOptions with documentationGenerated with Claude Code