anomalyco / anomalyco/opencode
The TUI cuts the end of a code block while it streams
@simonklee is already working on this.
Since Aug 20, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
The problem
The TUI does not show the end of a code block while the model writes it. The end of the block appears only after you reload the session.
The saved data is complete. So the problem is only in the streaming display of the TUI.
The cause
The content setter in Code.ts (package @opentui/core) does not update the text buffer when a code block streams
set content(value) {
if (this._content !== value) {
this._content = value;
this._highlightsDirty = true;
this._highlightSnapshotId++;
if (this._streaming && this._filetype && !this._drawUnstyledText) {
this.requestRender();
return; // The buffer stays old until the async highlight is ready.
}
// ...
}
}
During streaming, each new token cancels the last highlight result. The buffer never receives the new text. So the display stays short.
The proposed fix
Use the last highlight again for the stable part. Draw the new part without a highlight.
set content(value) {
if (this._content !== value) {
this._content = value;
this._highlightsDirty = true;
this._highlightSnapshotId++;
if (this._streaming && this._filetype && !this._drawUnstyledText) {
if (this._shouldRenderTextBuffer) {
if (this._lastHighlights.length > 0) {
const styledText = new StyledText(
treeSitterToTextChunks(value, this._lastHighlights, this._syntaxStyle, {
enabled: this._conceal,
baseHighlight: this._baseHighlight,
}),
);
this.textBuffer.setStyledText(styledText);
} else {
this.textBuffer.setText(value);
}
this.setRenderedLineSources(undefined);
this.updateTextInfo();
}
this.requestRender();
return;
}
// ...
}
}
This keeps the highlighted part and shows the new part at once. It does not flash unhighlighted code
Plugins
default
OpenCode version
1.18.15
Steps to reproduce
- Start the TUI
- Ask the model to write a long code block
- Watch the block while it streams. The text stops early
- Reload the session. The full block appears
Screenshot and/or share link
No response
Operating System
macos 26.5.2
Terminal
Terminal
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.