Introducing a new way to review your PRs.

Read the announcement

bas3line / ascii

Animated ascii art for web pages, in TypeScript: React, Next.js, Astro, or one HTML tag

View on GitHub

21 documents · Updated Oct 26, 2026

docs / terminal-and-output-rendering

Terminal and output rendering

The output layer turns a shared ASCII piece into terminal text, animated SVG, or a printed banner. Each path serves a different caller: interactive programs use terminal playback, documents use SVG, command output uses plain text, and library users select pieces and render them from TypeScript. See the Public rendering API for the wider rendering surface and Framework rendering adapters for browser framework use.

Rendering paths

The rendering paths share the piece contract but target different output environments. The caller chooses whether the result should occupy a live screen, remain in scrollback, travel as a string, or be loaded as a library value.

PathMain roleOutputTypical invocation
Terminal playbackShow moving art in an interactive CLIANSI terminal writesplay(piece) or npx ascii.rest <piece>
Still terminal outputSend art to a pipe, log, or redirected filePlain textstill(piece) or a non-TTY CLI run
SVG renderingEmbed art in a README, page, email, or image slotSelf-contained SVG stringsvg(piece) or npx ascii.rest svg <file.ts>
Printed bannerShow a name at CLI start and keep it in scrollbackTerminal text, with optional ANSI colorbanner(text) or npx ascii.rest banner <text>
Library loadingSelect a reusable or custom piece for another pathA Piece valueload[name]() or a piece import

The common flow is from a piece or banner source to a target-specific representation. The target controls motion, color, sizing, and the behavior of non-interactive output.

flowchart LR
  P[Piece or banner] --> T[Terminal playback]
  P --> S[Still text]
  P --> V[Animated SVG]
  B[Banner text] --> T
  B --> S
  B --> V
  L[Library or CLI invocation] --> P
  L --> B

Common piece contract

A Piece describes a named picture as a function of time. Renderers use its fixed cell size, motion rate, optional color palette, background, loop, and preferred still frame to preserve the same artwork across targets. (home/…/types.ts• L26-50, home/…/types.ts• L63-70)

The piece may be supplied as an imported value or resolved by name. This lets the library API and the CLI share the same rendering behavior without making callers know the piece file. (home/…/terminal.ts• L75-79, home/…/library.ts• L5-6)

References: home/…/types.ts• L26-50 home/…/types.ts• L63-70 home/…/library.ts• L5-6

Terminal rendering

Terminal rendering is the Node-only path for live CLI display. It presents a piece in a terminal-sized area and uses terminal control codes for screen state, color, cursor control, and frame updates.

Interactive playback

play is intended for a splash screen, a direct CLI command, or another interactive program. It centers the piece, adapts to terminal resize, and ends after a time limit, a key, an abort signal, Ctrl+C, or a terminal error. It restores the terminal before it resolves or fails. (home/…/terminal.ts• L1-16, home/…/terminal.ts• L251-267, home/…/terminal.ts• L329-421)

The renderer can show palette colors or use the terminal's own color. A light-terminal option changes the selected theme. A small terminal shows the middle of the piece and reports that cropping occurred so a caller can explain the result. (home/…/terminal.ts• L31-46, home/…/terminal.ts• L284-297)

Still terminal output

still produces one plain-text frame for a pipe, log, redirected output, or any caller that does not need motion. It uses the piece's preferred held frame when one exists and otherwise uses the first frame. (home/…/terminal.ts• L238-249)

The CLI selects this path when standard output is not a TTY. This makes commands useful in scripts and prevents ANSI screen control from entering files or downstream tools. (home/…/cli.ts• L397-402)

References: home/…/terminal.ts• L1-16 home/…/terminal.ts• L31-46 home/…/terminal.ts• L238-267 home/…/terminal.ts• L284-297 home/…/terminal.ts• L329-421 home/…/cli.ts• L397-410

SVG rendering

SVG rendering turns a piece into a portable string that can run without application script. It is intended for README images, web pages, email, image elements, server output, workers, and build-time generation. (home/…/svg.ts• L1-9)

Animated SVG output

svg samples a piece's loop and places its distinct frames in one SVG. CSS controls the frame changes, while reduced-motion settings select a stable frame. The result includes a view box, a text label, and a monospace layout so the cell grid stays aligned when displayed in different contexts. (home/…/svg.ts• L20-49, home/…/svg.ts• L64-145, home/…/svg.ts• L304-346)

The SVG path can select a light or dark theme, a start time, a duration, a sample rate, a one-time play, a scale, and an accessible label. It also keeps output size under a default budget by reducing frame rate and then color count when needed. (home/…/svg.ts• L201-225, home/…/svg.ts• L310-346)

SVG banner output

bannerSvg turns banner text into an SVG and can combine it with another piece or an SVG made by this library. It supports a tagline, layout around the artwork, theme-aware colors, a background, and motion that remains suitable for reduced-motion users. (home/…/svg.ts• L349-399, home/…/svg.ts• L455-521)

The CLI uses this path for a caller's own piece and either writes the SVG to a file or prints it. The CLI's svg command is therefore a build or export role, not an interactive terminal role. (home/…/cli.ts• L258-280)

References: home/…/svg.ts• L1-9 home/…/svg.ts• L20-49 home/…/svg.ts• L64-145 home/…/svg.ts• L184-225 home/…/svg.ts• L304-346 home/…/svg.ts• L349-399 home/…/svg.ts• L455-521 home/…/cli.ts• L258-280

Printed banners

The printed banner path presents text as block letters at the current terminal cursor. It is for a CLI name, start-up message, or other output that should remain in scrollback instead of taking over the screen. (home/…/print.ts• L1-10)

Scrollback output

banner animates a glint or typing effect once and then writes the completed banner and tagline as normal output. In a pipe it writes plain text at once. With NO_COLOR it keeps the motion behavior but removes color. A narrow or changing terminal falls back to a safe still result because in-place redraw is no longer reliable. (home/…/print.ts• L38-44, home/…/print.ts• L49-60, home/…/print.ts• L95-101, home/…/print.ts• L145-158)

The CLI exposes this path as npx ascii.rest banner <text>. Its options select the banner's font, shadow, effect, colors, tagline, and motion time. (home/…/cli.ts• L24-31, home/…/cli.ts• L360-388)

References: home/…/print.ts• L1-10 home/…/print.ts• L16-25 home/…/print.ts• L38-60 home/…/print.ts• L95-158 home/…/cli.ts• L24-31 home/…/cli.ts• L360-388

The banner source is a piece generator for text. It gives all output paths the same block-letter shape and motion model, so a banner can be mounted in a UI, played in a terminal, printed into scrollback, or exported as SVG. (home/…/banner.ts• L1-14)

banner accepts text and produces a named piece with a font, shadow, fill, effect, speed, color, and theme choices. Its motion describes whether the output glints in a loop, types once, or stays still. Renderers consume that motion rather than re-creating banner behavior for each format. (home/…/banner.ts• L269-327, home/…/banner.ts• L395-400, home/…/banner.ts• L558-577)

The package exposes this source through ascii.rest/banner. The terminal subpath re-exports the print wrapper, while the SVG subpath adds the SVG-specific composition wrapper. (home/…/package.json• L39-50, home/…/terminal.ts• L424-425)

References: home/…/banner.ts• L1-14 home/…/banner.ts• L269-327 home/…/banner.ts• L395-400 home/…/banner.ts• L558-577 home/…/terminal.ts• L424-425 home/…/package.json• L39-50

Library-oriented rendering

The library-oriented path lets TypeScript callers choose a piece first and then pass it to the output API that matches their environment. The same model supports built-in artwork, a named lazy load, or a custom piece supplied by a caller's file.

Named piece loading

load maps each public piece name to a lazy module loader. names supports discovery, and isPiece checks a name before a caller asks for it. The loaders are typed as promises of Piece modules, which keeps each selected artwork as a separate load unit for bundlers. (home/…/library.ts• L3-6, home/…/library.ts• L247-258)

The CLI uses the same name set for direct terminal playback and catalog listing. For custom work, play and svg accept one file whose default export is a piece, which makes the output paths useful during authoring as well as for the built-in library. (home/…/cli.ts• L184-186, home/…/cli.ts• L241-255, home/…/cli.ts• L258-280)

References: home/…/library.ts• L3-6 home/…/library.ts• L247-258 home/…/cli.ts• L184-186 home/…/cli.ts• L241-280

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the Piece frame size, palette, loop, and still-frame contract aligned with terminal and SVG consumers.
  • Keep non-TTY behavior plain-text so CLI pipes do not receive screen-control sequences.
  • Keep terminal cleanup and resize behavior aligned with any change to interactive playback or printed-banner redraws.
  • Keep SVG accessibility labels, reduced-motion behavior, and output-size limits aligned with changes to SVG frame sampling.
  • Keep package export subpaths and CLI command validation aligned when adding or renaming an output path.
  • Keep the generated load map, PieceName, names, and isPiece behavior aligned when the piece catalog changes.
  • Keep the canvas piece set aligned with the rendering surface that needs to distinguish colored pieces from preformatted pieces.

Important failure modes

TriggerConsequenceGuard
Terminal output is not a TTYLive playback has no screen to controlUse still or the CLI's non-TTY branch
Terminal is smaller than the pieceOnly the centered middle is visibleCheck Played.cropped and report the size mismatch
Terminal resize occurs during banner redrawIn-place rows may wrap and cannot be redrawn safelyStop the motion and leave the current output in scrollback
SVG loop or frame sample is too largeThe generated asset becomes slow to load or too large for a READMELet the SVG path reduce sampling and colors or set an explicit budget
A custom file does not export a pieceCLI playback or SVG export cannot resolve the sourceExport a piece as the file's default value
A piece name is missing from the generated load mapName checks and lazy loading reject or cannot resolve the pieceRegenerate the library map and keep its name and loader entries in sync

Key files

FileWhy to read it
src/types.tsDefines the shared piece and frame contract used by every output path.
src/terminal.tsShows live playback, still text, terminal sizing, and cleanup behavior.
src/print.tsShows scrollback-safe banner output and its TTY and pipe split.
src/svg.tsShows portable SVG output, motion handling, accessibility, and banner composition.
src/banner.tsDefines the banner source and the motion data consumed by other renderers.
src/library.tsDefines named piece loading, discovery, type narrowing, and the catalog's canvas classification for library and CLI callers.
src/cli.tsMaps user commands to terminal, still, SVG, banner, and custom-piece paths.
package.jsonDeclares the public terminal, banner, and svg package entry points.