Repository navigation
Don't clear over output printed outside of Terminal - #2130
Conversation
Summary: `Terminal` redraws its interactive status by moving the cursor up over the status lines and clearing to the end of the screen. Anything printed without going through `Terminal` (a dependency's `console.log`, `console.error`, Node deprecation warnings) lands inside that area and is erased by the next redraw. This keeps that output with a minimal change, without patching `console`, `process.stdout.write` or any other global: - After each status write, `Terminal` saves the stream's `bytesWritten`. When the stream is stdout or stderr, it uses the sum of both, as they usually share the terminal. - Before the next redraw, if the counter changed, something else printed after the status. `Terminal` then skips the cursor-up and clear and prints the new status below that output. - The writes of an update are issued without awaiting in between (`#updateSync`), so other output can't land between the cursor move, the clear and the new status. - The `--tty-print` help text in `fb-metro-cli` no longer says console output gets deleted by the status. Known limits: each time other output is detected, the previous status stays in the history above it. Output from child processes with `stdio: 'inherit'` or `fs.writeSync(1, ...)` doesn't move the counters and can still be erased. A piped stderr counts as other output even though it doesn't reach the screen, which only leaves an extra stale status. Differential Revision: D128348073
|
@vzaidman has exported this pull request. If you are a Meta employee, you can view the originating Diff in D128348073. |
Metro review: Looks goodRisk: low · Commit: The Findings
Verified
Not run: I couldn't do an end-to-end check in a real terminal: the sandbox has no PTY devices, and Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call. |
| return str.match(new RegExp(`(?:${SKIP_ANSI}.){1,${size}}`, 'g')) || []; | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
should fix · PR description is missing a Changelog line and a test plan
This changes what users see in Metro's interactive status output. Output from outside Terminal is now kept, and a stale copy of the previous status is left above it. The description has no Changelog: line and no test plan. Please add something like Changelog: [Fix] Don't erase console output printed outside of Metro's Terminal when updating the status, plus a short test plan (the new Terminal-test.js case and how the change was checked in a real terminal).
Evidence: I read pr.md. The description ends after 'Known limits' and the 'Differential Revision' line, with no Changelog: line and no test plan section. · id 8aca4b85
christophpurrer
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Summary:
Terminalredraws its interactive status by moving the cursor up over the status lines and clearing to the end of the screen. Anything printed without going throughTerminal(a dependency'sconsole.log,console.error, Node deprecation warnings) lands inside that area and is erased by the next redraw.This keeps that output with a minimal change, without patching
console,process.stdout.writeor any other global:Terminalsaves the stream'sbytesWritten. When the stream is stdout or stderr, it uses the sum of both, as they usually share the terminal.Terminalthen skips the cursor-up and clear and prints the new status below that output.#updateSync), so other output can't land between the cursor move, the clear and the new status.--tty-printhelp text infb-metro-clino longer says console output gets deleted by the status.Known limits: each time other output is detected, the previous status stays in the history above it. Output from child processes with
stdio: 'inherit'orfs.writeSync(1, ...)doesn't move the counters and can still be erased. A piped stderr counts as other output even though it doesn't reach the screen, which only leaves an extra stale status.Differential Revision: D128348073