spb/khaelor Public
KHAELOR — a terminal-native autonomous engineering agent powered by Anthropic.
TypeScript 82.9%
HTML 14.9%
CSS 1.1%
JavaScript 0.7%
1/**2 * KHAELOR3 * File: src/tui/components/sparkline.ts4 * Description: Braille sparkline — 2×4 dots per cell, used by /cost per-turn graphs (TUI v2 §3).5 *6 * Author: Simon-Pierre Boucher7 * Contact: contact@spboucher.ai8 */910// Braille dot bits by (column 0-1, row 0-3), per the Unicode braille block.11const DOT_BITS: number[][] = [12 [0x01, 0x02, 0x04, 0x40],13 [0x08, 0x10, 0x20, 0x80],14];1516/**17 * Render a numeric series as a braille sparkline: `⣀⣄⣤⣶⣿⣷⣄`. Two values per18 * cell, four vertical levels per dot column. Empty/flat series render as a19 * flat baseline — no fabricated variance (Absolute Rule #4).20 */21export function brailleSparkline(values: readonly number[], maxCells?: number): string {22 if (values.length === 0) return "";23 const max = Math.max(...values);24 const levels = values.map((value) => {25 if (max <= 0) return 1;26 return Math.max(1, Math.min(4, Math.ceil((value / max) * 4)));27 });28 const cellCount = Math.ceil(levels.length / 2);29 const cells: string[] = [];30 for (let cell = 0; cell < cellCount; cell += 1) {31 let bits = 0;32 for (let column = 0; column < 2; column += 1) {33 const level = levels[cell * 2 + column];34 if (level === undefined) continue;35 for (let row = 4 - level; row < 4; row += 1) {36 bits |= (DOT_BITS[column] as number[])[row] as number;37 }38 }39 cells.push(String.fromCharCode(0x2800 + bits));40 }41 const rendered = cells.join("");42 if (maxCells !== undefined && cells.length > maxCells) {43 return rendered.slice(cells.length - maxCells);44 }45 return rendered;46}47