prim-cliv0.5.0

Interactive prompts
for Node.js CLIs

Five keyboard-driven prompts, graceful cancellation, structured logging, and session framing. Zero dependencies. Node.js 16+.

GitHub❯ npx prim-cli

Introduction

prim-cli is a zero-dependency library of interactive terminal prompts for Node.js. Every prompt is pure keyboard — arrow keys, space, enter, escape — rendered with ANSI truecolor escape codes directly to stdout.

No React. No DOM. No browser. Install it, await a prompt, get a value back.

Installation

Zero dependencies. Works with Node.js 16+.

npm❯ npm install prim-clipnpm❯ pnpm add prim-cliyarn❯ yarn add prim-cli

Quick Start

Try the full interactive demo without installing anything:

❯ npx prim-cli

Or wire all five prompts together — with graceful Ctrl+C handling:

import { select, confirm, input, multiselect, spinner, intro, outro, note, log, cancel, isCancel, } from 'prim-cli' intro('create-my-app') const name = await input({ message: 'Project name' }) if (isCancel(name)) { cancel(); process.exit(0) } const fw = await select({ message: 'Framework', options: opts }) if (isCancel(fw)) { cancel(); process.exit(0) } const s = spinner({ message: 'Scaffolding...' }) await scaffold(name, fw) s.success('Done!') note('Next steps', `cd ${name} && npm run dev`) outro('Happy hacking!')
❯

select()

Single-choice selection. Arrow keys or j/k navigate, Enter confirms, Escape cancels. Returns a Promise<string>.

terminal
❯ node scaffold.js
?Which framework?
▲
Next.js
React framework for production
↵
◆
Nuxt
Vue framework with great DX
◈
SvelteKit
Cybernetically enhanced apps
✦
Astro
Content-focused static sites
◎
Remix
Full stack web framework
▶ click to focus · then use keyboard
Usage
import { select } from 'prim-cli' const framework = await select({ message: 'Which framework?', options: [ { value: 'next', label: 'Next.js', desc: 'React framework', icon: '▲' }, ] })
PropTypeDefaultDescription
messagestring—Prompt label shown above options
optionsOption[]—{ value, label, desc?, icon? }
◈

confirm()

Yes/no confirmation. Left/right arrows or y/n to toggle, Enter to confirm. Returns a Promise<boolean>.

terminal
❯ node deploy.js
?Deploy to production?
Yes
No
▶ click to focus · then use keyboard
Usage
import { confirm } from 'prim-cli' const ok = await confirm({ message: 'Deploy to production?', initial: true, })
PropTypeDefaultDescription
messagestring—Confirmation question
initialbooleantrueDefault selection
┃

input()

Free text input with live validation, placeholder text, and password masking. Returns a Promise<string>.

terminal
❯ node init.js
?Project name
›
── type · ↵ submit · esc cancel
Usage
import { input } from 'prim-cli' const name = await input({ message: 'Project name', placeholder: 'my-app', validate: (v) => v.length < 2 ? 'Too short' : null, })
PropTypeDefaultDescription
messagestring—Prompt label
placeholderstring""Dimmed hint text when empty
validate(v) => string|null—Return error string or null
typestring"text""text" or "password"
▣

multiselect()

Multi-choice selection. Arrow keys navigate, Space toggles, Enter confirms. Returns a Promise<string[]>.

terminal
❯ node setup.js
?Select features
✓
TypeScript
Strict type checking
ESLint
Code linting
✓
Prettier
Code formatting
Vitest
Unit testing
Husky
Git hooks
▶ click to focus · then use keyboard
Usage
import { multiselect } from 'prim-cli' const features = await multiselect({ message: 'Select features', options: ['TypeScript', 'ESLint', 'Prettier'].map(l => ({ label: l, value: l.toLowerCase() })),) required: false, })
PropTypeDefaultDescription
messagestring—Prompt label
optionsOption[]—{ value, label, desc? }
requiredbooleanfalseRequire at least one selection
◐

spinner()

Animated spinner with update, success, and error states. Returns a controller — not a Promise. Use it to wrap async work.

terminal
❯ node install.js
⠋Installing dependencies...
Usage
import { spinner } from 'prim-cli' const s = spinner({ message: 'Installing...' }) await install() s.update('Linking packages...') await link() s.success('Done!') // s.error('Failed') on catch
PropTypeDefaultDescription
messagestring—Initial spinner text
stylestring"dots"Animation: dots, line, moon, blocks, binary
s.update(msg)void—Change the spinner message mid-run
s.success(msg)void—Stop with a ✓ success message
s.error(msg)void—Stop with a ✕ error message
◆

ANSI Utilities

Truecolor styling, cursor control, and named color constants — built in to prim-cli, zero extra deps.

terminal
❯ node colors.js
✓ Deployed← c.green
✕ Failed← c.red
⚠ Warning← c.yellow
hint text← c.dim
important← c.bold
custom color← fg("#a78bfa")
Usage
import { c, fg, bg, cursor } from 'prim-cli' // c.* are ANSI escape prefix strings, not functions console.log(`${c.green}✓ Deployed${c.reset}`) console.log(`${c.red}✕ Failed${c.reset}`) console.log(`${c.bold}${c.violet}prim-cli${c.reset}`) // fg/bg take a hex string → return ANSI prefix console.log(fg('#a78bfa') + 'custom hex' + c.reset) // cursor strings for raw stdout writes process.stdout.write(cursor.hide)
PropTypeDefaultDescription
c.green / c.red / ...string—ANSI escape prefix for named colors
c.bold / c.dim / c.resetstring—Style prefix + reset sequence
fg(hex)string—Truecolor foreground ANSI prefix from hex
bg(hex)string—Truecolor background ANSI prefix from hex
cursor.hide / cursor.showstring—Raw ANSI cursor control strings
✕

isCancel() + cancel()

Every prompt resolves with the CANCEL symbol when the user presses Ctrl+C or Escape. Check with isCancel() — never === — and call cancel() to print a styled exit message.

terminal
❯ node setup.js
? Project name
› my-app
✕ Setup cancelled.
Usage
import { input, isCancel, cancel } from 'prim-cli' const name = await input({ message: 'Project name' }) if (isCancel(name)) { cancel('Setup cancelled.') process.exit(0) } // name is string here — TypeScript knows
PropTypeDefaultDescription
isCancel(value)boolean—Returns true if value is the CANCEL symbol (Ctrl+C or Escape)
cancel(message?)void"Operation cancelled."Print a red ✕ cancellation message to stdout
CANCELsymbol—The unique sentinel resolved on cancellation
┌

intro() + outro()

Frame your CLI with a banner at the start and a closing message at the end. Automatically adapts to terminal width.

terminal
❯ node setup.js
┌──────────────────────────────┐
│ ◆ create-my-app
└──────────────────────────────┘
✓ my-app Next.js TypeScript
┌──────────────────────────────┐
│ ✓ Done! Run cd my-app && npm run dev
└──────────────────────────────┘
Usage
import { intro, outro } from 'prim-cli' intro('create-my-app') // ... your prompts ... outro('Done! Run cd my-app && npm run dev')
PropTypeDefaultDescription
intro(title)void—Print an opening banner with ◆ and bold title
outro(message)void—Print a closing banner with ✓ and message
╭

note()

Print a titled info box — great for summaries, next steps, or any multi-line structured output.

terminal
❯ node setup.js
╭─ Next steps ─────────────────╮
│ cd my-app
│ npm install
│ npm run dev
╰──────────────────────────────╯
Usage
import { note } from 'prim-cli' note('Next steps', [`cd ${name}`, 'npm install', 'npm run dev'].join('\n'))
PropTypeDefaultDescription
titlestring—Box title shown in the top border
messagestring—Content — use \n for multiple lines
│

log.*

Structured log lines with consistent icon prefixes. Use these instead of console.log to keep your CLI output visually consistent.

terminal
❯ node build.js
ℹlog.infoUsing Node.js v20.11.0
⚠log.warnPeer dependency mismatch
✕log.errorFailed to resolve module
✓log.successBuild complete in 1.2s
◆log.stepRunning type check...
│
│ Multi-line note — stays
│ visually grouped.
│
Usage
import { log } from 'prim-cli' log.info('Using Node.js v20.11.0') log.warn('Peer dependency mismatch') log.error('Failed to resolve module') log.success('Build complete') log.step('Running type check...') // multi-line block with │ rail log.message('Line one\nLine two')
PropTypeDefaultDescription
log.info(msg)void—Blue ℹ icon — general info
log.warn(msg)void—Yellow ⚠ icon — warnings
log.error(msg)void—Red ✕ icon — errors
log.success(msg)void—Green ✓ icon — success
log.step(msg)void—Cyan ◆ icon — sequential steps
log.message(msg)void—Multi-line block with a │ rail