741ab06ed2
TUI: - Add fuzzy matching module (moved from coding-agent) - Remove Kitty protocol query timeout (fixes shift+enter delays) - Add bracketed paste check for key release/repeat detection - Rendering optimizations (only re-render changed lines) - Add backslash+enter newline fallback, getExpandedText() - Refactor input.ts to use keybindings manager Coding-agent: - Add /skill:name slash commands with enableSkillCommands setting - Add cwd to SessionInfo for session list display - Improve tree selector with custom summarization instructions - Add dequeue (Alt+Up) to restore all queued messages at once - Add shutdown request handling for extensions - Component invalidate() fixes for theme changes
102 lines
2.8 KiB
TypeScript
102 lines
2.8 KiB
TypeScript
import type { TextContent } from "@oh-my-pi/pi-ai";
|
|
import type { Component } from "@oh-my-pi/pi-tui";
|
|
import { Box, Container, Markdown, Spacer, Text } from "@oh-my-pi/pi-tui";
|
|
import type { HookMessageRenderer } from "../../../core/hooks/types";
|
|
import type { HookMessage } from "../../../core/messages";
|
|
import { getMarkdownTheme, theme } from "../theme/theme";
|
|
|
|
/**
|
|
* Component that renders a custom message entry from hooks.
|
|
* Uses distinct styling to differentiate from user messages.
|
|
*/
|
|
export class HookMessageComponent extends Container {
|
|
private message: HookMessage<unknown>;
|
|
private customRenderer?: HookMessageRenderer;
|
|
private box: Box;
|
|
private customComponent?: Component;
|
|
private _expanded = false;
|
|
|
|
constructor(message: HookMessage<unknown>, customRenderer?: HookMessageRenderer) {
|
|
super();
|
|
this.message = message;
|
|
this.customRenderer = customRenderer;
|
|
|
|
this.addChild(new Spacer(1));
|
|
|
|
// Create box with purple background (used for default rendering)
|
|
this.box = new Box(1, 1, (t) => theme.bg("customMessageBg", t));
|
|
|
|
this.rebuild();
|
|
}
|
|
|
|
setExpanded(expanded: boolean): void {
|
|
if (this._expanded !== expanded) {
|
|
this._expanded = expanded;
|
|
this.rebuild();
|
|
}
|
|
}
|
|
|
|
override invalidate(): void {
|
|
super.invalidate();
|
|
this.rebuild();
|
|
}
|
|
|
|
private rebuild(): void {
|
|
// Remove previous content component
|
|
if (this.customComponent) {
|
|
this.removeChild(this.customComponent);
|
|
this.customComponent = undefined;
|
|
}
|
|
this.removeChild(this.box);
|
|
|
|
// Try custom renderer first - it handles its own styling
|
|
if (this.customRenderer) {
|
|
try {
|
|
const component = this.customRenderer(this.message, { expanded: this._expanded }, theme);
|
|
if (component) {
|
|
// Custom renderer provides its own styled component
|
|
this.customComponent = component;
|
|
this.addChild(component);
|
|
return;
|
|
}
|
|
} catch {
|
|
// Fall through to default rendering
|
|
}
|
|
}
|
|
|
|
// Default rendering uses our box
|
|
this.addChild(this.box);
|
|
this.box.clear();
|
|
|
|
// Default rendering: label + content
|
|
const label = theme.fg("customMessageLabel", theme.bold(`[${this.message.customType}]`));
|
|
this.box.addChild(new Text(label, 0, 0));
|
|
this.box.addChild(new Spacer(1));
|
|
|
|
// Extract text content
|
|
let text: string;
|
|
if (typeof this.message.content === "string") {
|
|
text = this.message.content;
|
|
} else {
|
|
text = this.message.content
|
|
.filter((c): c is TextContent => c.type === "text")
|
|
.map((c) => c.text)
|
|
.join("\n");
|
|
}
|
|
|
|
// Limit lines when collapsed
|
|
if (!this._expanded) {
|
|
const lines = text.split("\n");
|
|
if (lines.length > 5) {
|
|
text = `${lines.slice(0, 5).join("\n")}\n${theme.format.ellipsis}`;
|
|
}
|
|
}
|
|
|
|
this.box.addChild(
|
|
new Markdown(text, 0, 0, getMarkdownTheme(), {
|
|
color: (text: string) => theme.fg("customMessageText", text),
|
|
}),
|
|
);
|
|
}
|
|
}
|