cli-kit
A small toolkit for the output side of a command-line tool. Colors, tables, spinners, progress bars, prompts and logs. It has no dependencies, and it prints plain lines when there is no terminal.
Spinners and progress bars often break in CI logs and pipes, and each one is a separate package with its own style. I wanted one small set that looks right in a terminal and still reads well in a log file.
What it does
Colors and tables
Chain styles like c.red.bold. Tables line up styled text, right-align numbers and fit the terminal width. Empty cells show a dash.
console.log(c.red.bold('error'), c.hex('#4f6df5')('brand'))
printTable(rows, { border: 'single', index: true })Spinners and progress bars
A spinner ends with a clear result line. A progress bar shows the percent, the count and the time left.
const spin = createSpinner('Installing…').start()
spin.log('fetched 42 packages')
spin.succeed('Done')
const bar = createProgressBar({ total: 100, label: 'migrate' })
bar.tick()Prompts
Text, password, yes or no, pick one and pick many. Use the arrow keys to move. Ctrl+C puts the terminal back the way it was.
const name = await input('Project name', { default: 'demo' })
const kind = await select('Template', [
{ value: 'lib', label: 'Library', hint: 'tsup + vitest' },
{ value: 'cli', label: 'CLI tool' },
{ value: 'app', label: 'Web app' },
])Logs
Levels, symbols and child loggers with a prefix. Warnings and errors go to stderr.
const log = createLogger({ level: 'info' })
log.success('applied', { ms: 182 })
log.warn('2 stale hints')
log.child('fin').info('scoped')Plain lines in CI and pipes
Without a terminal, nothing animates. A spinner prints one line when it starts and one when it ends. A progress bar prints at 0, 25, 50, 75 and 100 percent.
... Installing… ✓ Done migrate 0% (0/100) migrate 25% (25/100) migrate 50% (50/100) migrate 75% (75/100) migrate 100% (100/100)
- 06
Output only
It does not parse arguments. Pair it with a parser like commander.
Get started
- 1
Install
Node 18 or later. Works with ESM and CommonJS.
$npm i @dinesh-gamage/cli-kit - 2
Print a table
Pass an array of rows. Columns come from the keys.
import { printTable } from '@dinesh-gamage/cli-kit' printTable(rows, { border: 'single' }) - 3
Show progress
Start a spinner, then end it with a result.
import { createSpinner } from '@dinesh-gamage/cli-kit' const spin = createSpinner('Installing…').start() spin.succeed('Done')