Menu

Terminal & CLI

Sarmal works in the terminal, too.

Quick Try

npx @sarmal/core

That’s all that’s required to get one animating in your terminal. A random sarmal curve animates in your terminal using braille characters and ANSI colors. Ctrl+C to stop.

npx @sarmal/core --curve deltoid
npx @sarmal/core --curve rose3 --speed 2.5 --verbose

How It Works

Each terminal character maps to a 2x4 braille dot grid (Unicode U+2800-U+28FF). At the default size of 16 characters wide, you get a 32x32 effective dot grid. The curve auto-fits into the available space same way the canvas and SVG renderers do.

Color fading:

CapabilityDetected byEffect
TruecolorCOLORTERM=truecolor or TERM=*-truecolorSmooth per-channel RGB dimming
256-colorTERM=*-256colorNearest 216-color cube + 24 grayscale
MonochromeFallbackBraille dot density fades toward tail

The trail fades from full brightness at the head to 15% at the tail, linearly interpolated per RGB channel. The head cell is always rendered at full brightness with the head color.

CLI Options

npx @sarmal/core [options]
FlagTypeDefaultDescription
--curvestringRandomCurve name: deltoid, rose3, lissajous32, etc.
--fpsnumber30Frame rate
--speednumberCurve defaultAnimation speed multiplier
--sizenumber16Spinner width in characters
--colorstring#ec5571Trail color (#rrggbb, #rgb, rgb(), rgba())
--verboseflagoffPrint curve name and hint above the animation
--helpflag-Show usage

Node API

Import terminalSarmal directly for programmatic use:

import { terminalSarmal } from "@sarmal/core/terminal";
import { deltoid } from "@sarmal/core";

const stop = terminalSarmal(process.stdout, deltoid, {
  size: 20,
  fps: 60,
  speed: 3,
  trailColor: "#ff6b6b",
});

// Later...
stop();

Options

interface TerminalSarmalOptions {
  size?: number       // Width in chars. Default: 16 (32x32 dot grid)
  fps?: number        // Default: 30
  trailColor?: string // #rrggbb, #rgb, rgb(), rgba(). Default: "#ec5571"
  headColor?: string  // #rrggbb, #rgb, rgb(), rgba(). Default: trailColor
  speed?: number      // Default: curve's built-in speed
}

Environment Isolation

The ./terminal subpath export uses the node condition. Importing it in a browser project causes a build failure. It will not be silently included. Terminal code is never bundled into browser builds.

Info

terminalSarmal will do nothing when stdout is piped or not a TTY. Running in CI or redirecting output will silently skip rendering.

Lifecycle

terminalSarmal returns a stop() function. Calling it:

  • Clears the animation interval
  • Restores the cursor
  • Moves the cursor past the animation area

SIGINT (Ctrl+C) does the same cleanup automatically.

Available Curves

All 14 of the built-in curves are available by name.