Squashed 'third_party/pi/' content from commit d981de122

git-subtree-dir: third_party/pi
git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
This commit is contained in:
2026-09-14 10:40:08 -04:00
commit 67b361f0e9
1669 changed files with 397627 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import { Text } from "@earendil-works/pi-tui";
import { describe, expect, test } from "vitest";
import type { MessageRenderer, MessageRenderOptions } from "../src/core/extensions/types.ts";
import type { CustomMessage } from "../src/core/messages.ts";
import { CustomMessageComponent } from "../src/modes/interactive/components/custom-message.ts";
import { initTheme } from "../src/modes/interactive/theme/theme.ts";
import { stripAnsi } from "../src/utils/ansi.ts";
describe("CustomMessageComponent", () => {
test("provides output padding to custom renderers and updates it", () => {
initTheme("dark");
const optionsSeen: MessageRenderOptions[] = [];
const renderer: MessageRenderer = (_message, options) => {
optionsSeen.push(options);
return new Text("custom", options.outputPad, 0);
};
const message: CustomMessage = {
role: "custom",
customType: "test",
content: "custom",
display: true,
timestamp: Date.now(),
};
const component = new CustomMessageComponent(message, renderer, undefined, 1);
expect(optionsSeen).toEqual([{ expanded: false, outputPad: 1 }]);
expect(
component
.render(40)
.map(stripAnsi)
.some((line) => line.startsWith(" custom")),
).toBe(true);
component.setOutputPad(0);
expect(optionsSeen.at(-1)).toEqual({ expanded: false, outputPad: 0 });
expect(
component
.render(40)
.map(stripAnsi)
.some((line) => line.startsWith("custom")),
).toBe(true);
});
});