Terminal UI Target

Compile KERN to ANSI terminal interfaces with zero dependencies. Pure Node.js output using escape codes written directly to stdout.

What it generates

KERN input:

screen name=dashboard
  text value="Deploy Status" {color:blue,fw:bold}
  separator {width:48}
  box {color:green,width:50}
    text value="All systems operational"
    progress value=95 max=100 {color:green}
  spinner message="Checking services..." {color:cyan}

Compiled output (TypeScript, zero dependencies):

// ── ANSI helpers ──────────────────────────
const ESC = '\x1b[';
const RESET = ESC + '0m';
// ... (style, box, gradient, spinner, etc.)

// ── Output ─────────────────────────────────
console.log(style("Deploy Status", { color: "blue", bold: true }));
console.log(separator(48));
console.log(box("All systems operational\n[progress: 95/100]", "green", 50));
const _spinner = spinner("Checking services...", "cyan");
_spinner.start();

Supported nodes

The terminal transpiler handles these node types:

NodePropsDescription
textvalue, color, bg, bold, dim, italicStyled text output via console.log
separatorwidth (default 48)Horizontal line using dim characters
tableheaders, row children with dataAuto-width table with bold headers
scoreboardtitle, winner, metric childrenResults display with metrics and optional winner
spinnermessage, colorAnimated braille spinner (80ms interval)
progressvalue, max (default 100), colorBlock-character progress bar with percentage
boxcolor, width (default 50), childrenUnicode box-drawing frame around content
gradienttext, colors (array of ANSI 256 codes)Per-character color gradient
statename, initialMutable variable (let declaration)
handlercodeRaw code injection

REPL support

The terminal target has built-in REPL support using Node.js readline. Define interactive prompts with event handlers:

screen name=chatRepl
  state name=busy initial=false
  text value="Chat REPL" {fw:bold}
  repl prompt=">"
    guard busy
      text value="Waiting for response..." {color:yellow}
    on input
      handler <<<
        busy = true;
        const response = await getResponse(trimmed);
        console.log(response);
        busy = false;
      >>>
    on interrupt
      text value="Goodbye!" {color:dim}

This generates a complete readline-based REPL with a busy guard, input handler, and SIGINT cleanup.

Parallel dispatch

The terminal target supports parallel async dispatch with timeout and abort control. Use the parallel node to fan out work and collect results:

parallel timeout=30
  each engine in state.engines
    dispatch prompt=userPrompt result=response
      on start
        handler <<<
          console.log(style('Starting ' + engine, { dim: true }));
        >>>
      on done
        handler <<<
          console.log(style('Done: ' + engine, { color: 'green' }));
        >>>
  then
    handler <<<
      // results array contains all completed responses
      console.log('Finished: ' + results.length + ' responses');
    >>>

Color support

Colors can be specified as named colors (red, green, blue, cyan, magenta, yellow, white), hex codes (#ff6600), or ANSI 256 palette numbers. Bold, dim, and italic styles are supported on all text nodes.

Configuration

kern dev dashboard.kern --target=terminal

The generated .ts file runs directly with ts-node or tsx. No external dependencies required.