feat: integrate Pi backend and Pi Web

This commit is contained in:
luckyyzh
2026-07-30 19:37:53 +08:00
commit 7392ab9dd7
1390 changed files with 337197 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
import assert from "node:assert/strict";
import test from "node:test";
async function loadSubject() {
return import("./ansi.ts");
}
test("strips ANSI escape sequences", async () => {
const { stripAnsi } = await loadSubject();
assert.equal(stripAnsi("\x1b[31mred\x1b[0m plain"), "red plain");
assert.equal(stripAnsi("answer\x1b_pi:c\x07"), "answer");
});
test("normalizes boxed custom panel lines while preserving ANSI codes", async () => {
const { normalizeCustomPanelLines, stripAnsi } = await loadSubject();
const lines = [
"┌──────┐",
"│ \x1b[32mOK\x1b[0m │",
"└──────┘",
];
const normalized = normalizeCustomPanelLines(lines);
assert.equal(normalized.length, 1);
assert.equal(stripAnsi(normalized[0]), "OK");
assert.match(normalized[0], /\x1b\[32m/);
});
test("removes pi-tui cursor markers from custom panel output", async () => {
const { normalizeCustomPanelLines } = await loadSubject();
assert.deepEqual(normalizeCustomPanelLines(["> value\x1b_pi:c\x07"]), ["> value"]);
});
test("parses ANSI style segments and reset codes", async () => {
const { parseAnsiLine } = await loadSubject();
assert.deepEqual(parseAnsiLine("\x1b[31;1mhot\x1b[0m cold"), [
{ text: "hot", style: { color: "#dc2626", fontWeight: 700 } },
{ text: " cold", style: {} },
]);
});
test("maps 256-color SGR codes", async () => {
const { ansi256Color, parseAnsiLine } = await loadSubject();
assert.equal(ansi256Color(196), "rgb(255, 0, 0)");
assert.deepEqual(parseAnsiLine("\x1b[38;5;196mred"), [
{ text: "red", style: { color: "rgb(255, 0, 0)" } },
]);
});