Something went wrong

Thank you for being patient! We're working hard on resolving the issue

formatTable + runRepl - Lona Docs Log in

Library Surface

@tento-lona/cli/rows-fixtures ships two functions usable as a library — embed the rows-CLI rendering / REPL inside another tool without shelling out.

import { formatTable, runRepl } from "@tento-lona/cli/rows-fixtures";

formatTable(sheet, opts?): string

Render a Sheet as a rows × dates grid. Same output as hydrate but as a string rather than written to stdout.

import { Sheet, TestBackend } from "@tento-lona/sheets";
import { formatTable } from "@tento-lona/cli/rows-fixtures";

const sheet = await Sheet.from(rawSheet, { backend: new TestBackend() });

const grid = formatTable(sheet);
console.log(grid);

// No ANSI escapes — useful for plain-text logs:
const plain = formatTable(sheet, { color: false });

Options

interface FormatOptions {
  color?: boolean;   // default: true (honors NO_COLOR)
}

The color: false mode is what --json uses internally for the embedded snapshot.cells rendering (so snapshot diffs aren't polluted by escape codes).

runRepl(sheet): Promise<void>

Stdin-driven REPL over a hydrated Sheet. Same commands as watch; useful for embedding the REPL in a host program that constructs the sheet differently (e.g. from a database fixture):

import { Sheet } from "@tento-lona/sheets";
import { runRepl } from "@tento-lona/cli/rows-fixtures";

const sheet = await loadSheetFromMyDatabase();   // your code
await runRepl(sheet);    // resolves when user types `quit`

The function consumes stdin until quit/exit or EOF. Any mutations the user makes via set / formula / etc. land on the same sheet object you passed in — you can inspect / serialize after the call returns.

When to embed vs. shell out

Embed (formatTable / runRepl) when:

  • You need to construct the Sheet yourself (test harness, database loader, custom backend).
  • You want to inspect the REPL's resulting Sheet post-quit.
  • You're building a higher-level tool that wraps the rows-CLI.

Shell out (deno run ...) when:

  • The starting state is already a .sheet.json on disk.
  • You want the standard CLI flag handling (--save-on-exit, fixture path resolution).
  • You're writing a shell script or one-liner.

See also

  • Introduction — the CLI commands
  • tento/tento-lona-js/cli/rows-fixtures/src/lib.ts — full library surface (small; mostly re-exports formatTable + runRepl)