Library

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.

Why I built it

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.

LibrariesDev toolsv0.1.0MITNode 18+No dependenciesOpen source
On npm
1 / 2
Features

What it does

01

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.

colors.js
console.log(c.red.bold('error'), c.hex('#4f6df5')('brand'))

printTable(rows, { border: 'single', index: true })
Colors, a table and a box
02

Spinners and progress bars

A spinner ends with a clear result line. A progress bar shows the percent, the count and the time left.

install.js
const spin = createSpinner('Installing…').start()
spin.log('fetched 42 packages')
spin.succeed('Done')

const bar = createProgressBar({ total: 100, label: 'migrate' })
bar.tick()
Two spinners and a progress bar
03

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.

create.js
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' },
])
A text prompt and a select prompt
04

Logs

Levels, symbols and child loggers with a prefix. Warnings and errors go to stderr.

build.js
const log = createLogger({ level: 'info' })
log.success('applied', { ms: 182 })
log.warn('2 stale hints')
log.child('fin').info('scoped')
Each log level
05

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.

node install.js | cat
... 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.

How to use

Get started

Read the full docs
  1. 1

    Install

    Node 18 or later. Works with ESM and CommonJS.

    $npm i @dinesh-gamage/cli-kit
  2. 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. 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')