UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

61 lines • 2.73 kB
import { Container, Markdown } from "@earendil-works/pi-tui"; import { sharedMarkdownTheme, theme } from "../theme/theme.js"; import { AskUserAnswerChip, parseAskUserAnswerFrame } from "./ask-user-answer-chip.js"; import { createMarkdownTransform } from "./markdown-transform.js"; const OSC133_ZONE_START = "\x1b]133;A\x07"; const OSC133_ZONE_END = "\x1b]133;B\x07"; const OSC133_ZONE_FINAL = "\x1b]133;C\x07"; /** * Component that renders a user message */ export class UserMessageComponent extends Container { constructor(text, markdownTheme = sharedMarkdownTheme(), outputPad = 1, markdownTransformers = [], answerHeaders = []) { super(); this.text = text; this.markdownTheme = markdownTheme; this.outputPad = outputPad; this.markdownTransformers = markdownTransformers; this.answerHeaders = answerHeaders; this.rebuild(); } setOutputPad(padding) { this.outputPad = padding; this.rebuild(); } rebuild() { this.clear(); // The Markdown pads and colors its own background: a Box around it would keep a second full-width copy of every // line, with identical output. const contentBox = new Markdown(this.text, this.outputPad, 1, this.markdownTheme, { color: (content) => theme.fg("userMessageText", content), bgColor: (content) => theme.bg("userMessageBg", content), }, { preserveOrderedListMarkers: true, preserveBackslashEscapes: true, transform: createMarkdownTransform("user", false, this.markdownTransformers), }); const answer = parseAskUserAnswerFrame(this.text); this.addChild(answer ? new AskUserAnswerChip(answer, this.answerHeaders, contentBox) : contentBox); } /** Output is the zone-marked render of the content box, so it changes only with that subtree. */ getRenderRevision() { return this.childRenderRevision(); } render(width) { const lines = super.render(width); if (lines.length === 0) { return lines; } // A one-line render (the compact answer chip) is both first and last line, // so the closing markers append instead of prefixing themselves ahead of // the opening one. Taller messages keep the markers off the line end. if (lines.length === 1) { lines[0] = OSC133_ZONE_START + lines[0] + OSC133_ZONE_END + OSC133_ZONE_FINAL; return lines; } lines[0] = OSC133_ZONE_START + lines[0]; lines[lines.length - 1] = OSC133_ZONE_END + OSC133_ZONE_FINAL + lines[lines.length - 1]; return lines; } } //# sourceMappingURL=user-message.js.map