mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 06:04:51 +00:00
fix(widgets): add max line limit and document multi-hook behavior
- Limit total widget lines to 10 to prevent viewport overflow/flicker - Show '... (widget truncated)' when limit exceeded - Document that multiple hooks stack widgets vertically - Add caution about keeping widgets small
This commit is contained in:
parent
78d4d44ab7
commit
705e92e43f
2 changed files with 14 additions and 2 deletions
|
|
@ -445,9 +445,10 @@ const currentText = ctx.ui.getEditorText();
|
||||||
|
|
||||||
**Widget notes:**
|
**Widget notes:**
|
||||||
- Widgets are multi-line displays shown above the editor (below "Working..." indicator)
|
- Widgets are multi-line displays shown above the editor (below "Working..." indicator)
|
||||||
- Multiple hooks can set widgets using unique keys
|
- Multiple hooks can set widgets using unique keys (all widgets are displayed, stacked vertically)
|
||||||
- Use for progress lists, todo tracking, or any multi-line status
|
- Use for progress lists, todo tracking, or any multi-line status
|
||||||
- Supports ANSI styling via `ctx.ui.theme` (including `strikethrough`)
|
- Supports ANSI styling via `ctx.ui.theme` (including `strikethrough`)
|
||||||
|
- **Caution:** Keep widgets small (a few lines). Large widgets from multiple hooks can cause viewport overflow and TUI flicker.
|
||||||
|
|
||||||
**Styling with theme colors:**
|
**Styling with theme colors:**
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -637,6 +637,9 @@ export class InteractiveMode {
|
||||||
this.renderWidgets();
|
this.renderWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Maximum total widget lines to prevent viewport overflow
|
||||||
|
private static readonly MAX_WIDGET_LINES = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render all hook widgets to the widget container.
|
* Render all hook widgets to the widget container.
|
||||||
*/
|
*/
|
||||||
|
|
@ -649,10 +652,18 @@ export class InteractiveMode {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render each widget
|
// Render each widget, respecting max lines to prevent viewport overflow
|
||||||
|
let totalLines = 0;
|
||||||
for (const [_key, lines] of this.hookWidgets) {
|
for (const [_key, lines] of this.hookWidgets) {
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
|
if (totalLines >= InteractiveMode.MAX_WIDGET_LINES) {
|
||||||
|
// Add truncation indicator and stop
|
||||||
|
this.widgetContainer.addChild(new Text(theme.fg("muted", "... (widget truncated)"), 1, 0));
|
||||||
|
this.ui.requestRender();
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.widgetContainer.addChild(new Text(line, 1, 0));
|
this.widgetContainer.addChild(new Text(line, 1, 0));
|
||||||
|
totalLines++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue