Display table in terminal
npm install @oclif/table



Print beautiful, flexible tables to the terminal using Ink. This library powers many oclif/Salesforce CLIs and is built for real-world, production output: wide columns, multi-line cells, smart wrapping/truncation, theming, and great CI behavior.
- Rich rendering via Ink with graceful fallback to plain text in CI
- Automatic column sizing with max/explicit width support (including percentages)
- Per-column alignment, padding, and overflow control (wrap, truncate, middle/start/end)
- Header formatting with change-case presets or custom function
- Multiple border styles (outline, headers-only, vertical/horizontal, none, and more)
- Sort and filter data, optionally per-column
- Print multiple tables side-by-side or stacked with layout controls
- Return a string (makeTable) or print directly (printTable/printTables)
- TypeScript-first API with excellent types
---
- Node.js >= 18
- ESM only (this package has "type": "module"). Use import, not require.
``bash`
npm install @oclif/tableor
yarn add @oclif/tableor
pnpm add @oclif/tableor
bun add @oclif/table
`js
import {printTable} from '@oclif/table'
const data = [
{name: 'Alice', role: 'Engineer', notes: 'Loves distributed systems'},
{name: 'Bob', role: 'Designer', notes: 'Enjoys typography and UI'},
]
printTable({
title: 'Team',
data,
columns: [
{key: 'name', width: 16},
{key: 'role', width: 14, horizontalAlignment: 'center'},
{key: 'notes', overflow: 'wrap'},
],
})
`
To generate a string instead of printing to stdout:
`js
import {makeTable} from '@oclif/table'
const output = makeTable({data, columns: ['name', 'role', 'notes']})
// do something with output`
To print multiple tables in one layout:
`js
import {printTables} from '@oclif/table'
printTables(
[
{title: 'Developers', data, columns: ['name', 'role']},
{title: 'Notes', data, columns: ['notes']},
],
{direction: 'row', columnGap: 4, margin: 1},
)
`
---
- printTable(options) — renders a single table to stdout.makeTable(options): string
- — renders a single table and returns the output string.printTables(tables, options?)
- — renders multiple tables with layout controls.
All three accept the same TableOptions (documented below). printTables accepts an array of TableOptions plus optional container layout props.
#### TypeScript
`ts
import type {TableOptions} from '@oclif/table'
type Row = {name: string; age: number}
const opts: TableOptions
data: [{name: 'Ada', age: 36}],
columns: [
{key: 'name', name: 'Full Name'},
{key: 'age', horizontalAlignment: 'right'},
],
}
`
---
Below are the most important options with defaults and behavior. See examples in ./examples for more patterns.
- data (required): array of rows, each a plain object.columns
- : list of keys or objects describing each column.'name'
- String form: (uses key as header){ key, name?, width?, padding?, overflow?, horizontalAlignment?, verticalAlignment? }
- Object form: name
- : header label (defaults to key or formatted with headerOptions.formatter)width
- : number of characters or percentage string like '50%'padding
- : spaces added on both sides (default: table padding)overflow
- : 'wrap' | 'truncate' | 'truncate-start' | 'truncate-middle' | 'truncate-end'horizontalAlignment
- : 'left' | 'center' | 'right'verticalAlignment
- : 'top' | 'center' | 'bottom'
- padding (number): cell padding for all columns. Default: 1.
- maxWidth (number | percentage | 'none'): maximum table width. Defaults to terminal width.maxWidth
- When the natural table width exceeds , columns shrink and content wraps/truncates based on overflow.'none'
- Use to allow unlimited width (useful for very wide outputs; users can resize their terminals).
- width (number | percentage): exact table width. Overrides maxWidth. If wider than the natural width, columns expand evenly.
- overflow: cell overflow behavior. Default: 'truncate'.'wrap'
- wraps long content'truncate'
- truncates the end'truncate-start' | 'truncate-middle' | 'truncate-end'
- choose truncation position
- headerOptions: style options for headers.formatter
- : either a function (header: string) => string or a change-case preset name:'camelCase' | 'capitalCase' | 'constantCase' | 'kebabCase' | 'pascalCase' | 'sentenceCase' | 'snakeCase'
titleOptions
- Styling keys (also supported by ):color
- , backgroundColor (named color, hex #rrggbb, or rgb(r,g,b))bold
- , dimColor, italic, underline, strikethrough, inversenoStyle: true
- Default header style is bold blue (unless ).
- borderStyle: border preset. Default: 'all'.'all' | 'headers-only' | 'headers-only-with-outline' | 'headers-only-with-underline' | 'horizontal' | 'horizontal-with-outline' | 'none' | 'outline' | 'vertical' | 'vertical-rows-with-outline' | 'vertical-with-outline'
- Available:
- borderColor: optional border color. When unset, the terminal's default color is used.
- horizontalAlignment: default column alignment. Default: 'left'.
- verticalAlignment: default vertical alignment within cells. Default: 'top'.
- filter(row): predicate to include/exclude rows.
- sort: object mapping keys to 'asc' | 'desc' | (a,b)=>number. Keys order defines multi-column priority.
- title: optional string printed above the table.
- titleOptions: style options for the title (same keys as headerOptions except formatter).
- trimWhitespace: when wrapping text, trim whitespace at line boundaries. Default: true.
- noStyle: disable all styling. Also strips ANSI color codes from your cell content for accurate width calculation.
#### Container options (for printTables)
printTables(tables, containerOptions) accepts:
- direction: 'row' | 'column' (default 'row')columnGap
- , rowGap: spacing between tablesalignItems
- : 'flex-start' | 'center' | 'flex-end'margin
- , marginLeft, marginRight, marginTop, marginBottom
---
- Terminal width detection: by default we use your terminal width. Override with OCLIF_TABLE_COLUMN_OVERRIDE.OCLIF_TABLE_COLUMN_OVERRIDE=120 node app.js
- Example:
- CI-safe output: in CI environments, we automatically fall back to a plain-text renderer (no Ink) for stability.
- To force Ink rendering in CI, set OCLIF_TABLE_SKIP_CI_CHECK=1.
- Very large data: by default, datasets with 10,000+ rows use the plain-text renderer to avoid memory issues.
- Override with OCLIF_TABLE_LIMIT= (Salesforce CLIs may also honor SF_TABLE_LIMIT).
---
Header formatting with change-case:
`js
import {printTable} from '@oclif/table'
printTable({
data: [{first_name: 'Ada', last_name: 'Lovelace'}],
columns: ['first_name', 'last_name'],
headerOptions: {formatter: 'capitalCase'},
})
`
Per-column sizing and overflow:
`js`
printTable({
data: [{name: 'A very very long name', notes: 'Multi-line\ncontent supported'}],
maxWidth: '80%',
columns: [
{key: 'name', width: 20, overflow: 'truncate-middle'},
{key: 'notes', overflow: 'wrap', horizontalAlignment: 'right'},
],
})
Switching borders and colors:
`js`
printTable({
title: 'Inventory',
titleOptions: {bold: true, color: 'cyan'},
data: [{item: 'Widget', qty: 10}],
columns: ['item', {key: 'qty', horizontalAlignment: 'right'}],
borderStyle: 'vertical-with-outline',
borderColor: 'green',
})
---
This repo contains many runnable examples in ./examples (including edge cases like very wide/very tall tables). Run any with:
`bash`
tsx examples/basic.ts
---
This package includes snapshot tests for all examples to ensure consistent output across different environments.
#### Running tests
`bashRun all tests (including snapshot tests)
yarn test
#### How snapshot testing works
Examples are executed in an isolated child process with:
- Fixed terminal width (
OCLIF_TABLE_COLUMN_OVERRIDE=120)
- Disabled CI detection unless an example sets it
- ESM loader for TypeScript (ts-node/esm)Snapshots live in
test/__snapshots__/examples/*.txt and mirror the examples` directory structure.---
See the contributing guide.
MIT © Salesforce