8ef11355e7
- Added native text utilities in pi-natives (visible width, truncation, slicing, segment extraction) - Wired pi-tui to use native implementations with short-string JS fast path - Optimized key matching via cached parsed key ids - Refactored visual truncation to reuse Text instances - Reduced theme color lookups by switching from Map to plain records - Regenerated WASM artifacts Benchmarks (after vs before, lower is better): - truncateToWidth/ansi: 20.37ms vs 38.13ms (2000 iters) - sliceWithWidth/ansi: 5.12ms vs 20.39ms - extractSegments/ansi: 8.92ms vs 27.60ms - truncateToVisualLines: 3.51ms vs 411.55ms (500 iters) - visibleWidth/ansi: 0.24ms vs 0.31ms
21 lines
635 B
TypeScript
21 lines
635 B
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { Key, matchesKey, setKittyProtocolActive } from "@oh-my-pi/pi-tui/keys";
|
|
|
|
describe("matchesKey", () => {
|
|
it("matches ctrl+letter sequences", () => {
|
|
setKittyProtocolActive(false);
|
|
const ctrlC = String.fromCharCode(3);
|
|
expect(matchesKey(ctrlC, Key.ctrl("c"))).toBe(true);
|
|
});
|
|
|
|
it("matches shifted tab", () => {
|
|
setKittyProtocolActive(false);
|
|
expect(matchesKey("\x1b[Z", "shift+tab")).toBe(true);
|
|
});
|
|
|
|
it("matches pageUp legacy sequence with mixed case keyId", () => {
|
|
setKittyProtocolActive(false);
|
|
expect(matchesKey("\x1b[5~", "pageUp")).toBe(true);
|
|
});
|
|
});
|