-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(cli): replace clearTerminal with targeted repaint on resize #3967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -367,6 +367,7 @@ export const AppContainer = (props: AppContainerProps) => { | |
|
|
||
| // Terminal and layout hooks | ||
| const { columns: terminalWidth, rows: terminalHeight } = useTerminalSize(); | ||
| const previousTerminalWidthRef = useRef(terminalWidth); | ||
| const { stdin, setRawMode } = useStdin(); | ||
| const { stdout } = useStdout(); | ||
|
|
||
|
|
@@ -563,6 +564,13 @@ export const AppContainer = (props: AppContainerProps) => { | |
| remountStaticHistory(); | ||
| }, [remountStaticHistory, stdout]); | ||
|
|
||
| // Targeted repaint for resize events: move cursor to top-left and erase | ||
| // downward instead of a full clearTerminal, avoiding the full-screen flash. | ||
| const repaintStaticViewport = useCallback(() => { | ||
| stdout.write(`${ansiEscapes.cursorTo(0, 0)}${ansiEscapes.eraseDown}`); | ||
| remountStaticHistory(); | ||
| }, [remountStaticHistory, stdout]); | ||
|
|
||
| // Keep the static header in sync with model changes without polling. | ||
| // Ink's <Static> output is append-only, so model changes must explicitly | ||
| // clear and remount the static region to redraw the banner at the top. | ||
|
|
@@ -1747,6 +1755,14 @@ export const AppContainer = (props: AppContainerProps) => { | |
| } | ||
| }, [terminalWidth, availableTerminalHeight, activePtyId]); | ||
|
|
||
| useEffect(() => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] 新增的 resize effect( — DeepSeek/deepseek-v4-pro via Qwen Code /review |
||
| if (previousTerminalWidthRef.current === terminalWidth) { | ||
| return; | ||
| } | ||
| previousTerminalWidthRef.current = terminalWidth; | ||
| repaintStaticViewport(); | ||
| }, [terminalWidth, repaintStaticViewport]); | ||
|
|
||
| useEffect(() => { | ||
| if (ideNeedsRestart) { | ||
| // IDE trust changed, force a restart. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion]
repaintStaticViewport回调和新 width-changeuseEffect缺少测试覆盖。repaintStaticViewport是未导出的私有回调,现有 56 个 AppContainer 测试中没有测试能触发它。建议至少新增以下测试:(1) 通过 actions context 暴露该回调并验证其写入cursorTo(0,0) + eraseDown;(2) 宽度变化时验证 effect 写入正确转义序列;(3) 等值守卫(80→80)时验证不写入任何转义序列。另外,现有测试 "does not clear the terminal just because width changed" (AppContainer.test.tsx:501) 仅断言旧行为(
clearTerminal未写入),应同步更新为验证新行为(cursorTo + eraseDown已写入),避免未来回归被掩盖。— DeepSeek/deepseek-v4-pro via Qwen Code /review