Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

4.6 KB
Raw Blame
/**
 * Pixel/block-font renderer for the Mercury Code splash screen.
 *
 * Each glyph is a fixed-width bitmap (1 = filled). All glyphs in a word
 * share one baseline and one column width, and rows are padded — never
 * ragged — so concatenating a second word cannot misalign rows. Filled
 * cells use single-codepoint block characters only (U+2588/U+2593), which
 * every terminal font metrics-treats as exactly one cell wide: the mark is
 * pixel-precise across devices. Color/vibrancy is applied by the caller.
 *
 * Shading is applied PER ROW (top→bottom), never per column. A per-column
 * cycle landed shade cells at different positions on every row — visible
 * holes inside letters (`█ ▓ █`). Per-row shading gives every letter the
 * same consistent banding, so a trailing shade reads as a deliberate
 * vertical gradient instead of random gaps.
 */

const GLYPHS: Record<string, string[]> = {
  A: [
    '0110',
    '1001',
    '1111',
    '1001',
    '1001',
  ],
  B: [
    '1110',
    '1001',
    '1110',
    '1001',
    '1110',
  ],
  C: [
    '0111',
    '1000',
    '1000',
    '1000',
    '0111',
  ],
  D: [
    '1110',
    '1001',
    '1001',
    '1001',
    '1110',
  ],
  E: [
    '1111',
    '1000',
    '1110',
    '1000',
    '1111',
  ],
  G: [
    '0111',
    '1000',
    '1011',
    '1001',
    '0111',
  ],
  H: [
    '1001',
    '1001',
    '1111',
    '1001',
    '1001',
  ],
  I: [
    '111',
    ' 1 ',
    ' 1 ',
    ' 1 ',
    '111',
  ],
  M: [
    '10001',
    '11011',
    '10101',
    '10001',
    '10001',
  ],
  N: [
    '1001',
    '1101',
    '1011',
    '1001',
    '1001',
  ],
  O: [
    '0110',
    '1001',
    '1001',
    '1001',
    '0110',
  ],
  P: [
    '1110',
    '1001',
    '1110',
    '1000',
    '1000',
  ],
  R: [
    '1110',
    '1001',
    '1110',
    '1010',
    '1001',
  ],
  S: [
    '0111',
    '1000',
    '0110',
    '0001',
    '1110',
  ],
  T: [
    '111',
    ' 1 ',
    ' 1 ',
    ' 1 ',
    ' 1 ',
  ],
  U: [
    '1001',
    '1001',
    '1001',
    '1001',
    '0110',
  ],
  V: [
    '10001',
    '10001',
    '10001',
    '01010',
    '00100',
  ],
  W: [
    '10001',
    '10001',
    '10101',
    '11011',
    '10001',
  ],
  X: [
    '10001',
    '01010',
    '00100',
    '01010',
    '10001',
  ],
  Y: [
    '1001',
    '1001',
    '0110',
    '0110',
    '0110',
  ],
  Z: [
    '1111',
    '0001',
    '0110',
    '1000',
    '1111',
  ],
  ' ': [
    '  ',
    '  ',
    '  ',
    '  ',
    '  ',
  ],
};

export const PIXEL_FONT_HEIGHT = 5;

/**
 * Render a word as pixel-font rows.
 * @param shading Block characters applied PER ROW, top→bottom (e.g.
 *   '████▓' = three solid rows then two shaded — a subtle vertical
 *   gradient shadow under every letter, consistent across the mark).
 *   Defaults to solid fill. A shaded cell never appears above a solid one
 *   in the same letter, so shading can never read as a mid-letter hole.
 */
export function renderPixelWord(word: string, shading: string = '█'): string[] {
  const fills = shading.length > 0 ? shading.split('') : ['█'];
  const rows: string[] = Array.from({ length: PIXEL_FONT_HEIGHT }, () => '');
  for (const ch of word.toUpperCase()) {
    const glyph = GLYPHS[ch] ?? GLYPHS[' '];
    for (let y = 0; y < PIXEL_FONT_HEIGHT; y++) {
      const glyphRow = glyph[y] ?? '';
      const fill = y < fills.length ? fills[y] : fills[fills.length - 1];
      let rendered = '';
      for (const bit of glyphRow) {
        rendered += bit === '1' ? fill : ' ';
      }
      rows[y] += rendered + ' ';
    }
  }
  return rows;
}

/**
 * Two-tone "MERCURY CODE" as alignment-safe parts for colored rendering.
 * The left block ("MERCURY") is padded to a constant width so the right
 * block ("CODE") starts at the same column on every row — pixel-precise
 * on any terminal. Fully SOLID fill: shaded bands read as gaps between
 * blocks in real terminal fonts, so every filled cell is a bright block.
 */
export function renderMercuryCodeParts(): Array<{ left: string; right: string }> {
  const mercury = renderPixelWord('MERCURY', '█');
  const code = renderPixelWord('CODE', '█');
  const trimEnd = (s: string) => s.replace(/\s+$/, '');
  const leftTrimmed = mercury.map(trimEnd);
  const leftW = Math.max(...leftTrimmed.map((r) => r.length));
  return leftTrimmed.map((row, i) => ({
    left: row.padEnd(leftW, ' '),
    right: trimEnd(code[i] ?? ''),
  }));
}

/** Flat two-tone splash (single string per row). Kept for simple dumps. */
export function renderMercuryCodeSplash(): string[] {
  return renderMercuryCodeParts().map(({ left, right }) =>
    `${left}  ${right}`.replace(/\s+$/, ''),
  );
}