CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-prompts

Lightweight, beautiful and user-friendly interactive CLI prompts library with promise-based API

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

confirmation-prompts.mddocs/

Confirmation and Toggle Prompts

Binary choice prompts for yes/no confirmations, toggle switches, and list input. These prompts handle simple binary decisions and comma-separated list input with custom formatting options.

const prompts = require('prompts');

Capabilities

Confirm Prompt

Classic yes/no confirmation prompt. Users can press Y/N keys or use arrow keys to select Yes/No options.

{
  /** Prompt type identifier */
  type: 'confirm',
  /** Property name for response object */
  name: string,
  /** Display message for user */
  message: string,
  /** Default boolean value. Defaults to false */
  initial?: boolean,
  /** Custom formatter for boolean value */
  format?: (value: boolean, values: Answers) => any,
  /** Render callback with kleur styling */
  onRender?: (kleur: any) => void,
  /** State change callback */
  onState?: (state: { value: boolean; aborted: boolean }) => void,
  /** Input stream */
  stdin?: NodeJS.ReadableStream,
  /** Output stream */
  stdout?: NodeJS.WritableStream
}

Usage Examples:

const prompts = require('prompts');

// Basic confirmation
const response = await prompts({
  type: 'confirm',
  name: 'continue',
  message: 'Do you want to continue?',
  initial: true
});

// Confirmation with custom formatting
const response = await prompts({
  type: 'confirm',
  name: 'subscribe',
  message: 'Subscribe to newsletter?',
  initial: false,
  format: value => value ? 'Subscribed' : 'Not subscribed'
});

// Confirmation in a sequence
const questions = [
  {
    type: 'text',
    name: 'name',
    message: 'Enter your name:'
  },
  {
    type: 'confirm',
    name: 'isCorrect',
    message: (prev, values) => `Is "${values.name}" correct?`,
    initial: true
  }
];

const response = await prompts(questions);

Toggle Prompt

Interactive toggle/switch prompt with custom labels for active and inactive states. Users can use arrow keys, Tab, or Space to switch between states.

{
  /** Prompt type identifier */
  type: 'toggle',
  /** Property name for response object */
  name: string,
  /** Display message for user */
  message: string,
  /** Default boolean value. Defaults to false */
  initial?: boolean,
  /** Text for active/true state. Defaults to 'on' */
  active?: string,
  /** Text for inactive/false state. Defaults to 'off' */
  inactive?: string,
  /** Custom formatter for boolean value */
  format?: (value: boolean, values: Answers) => any,
  /** Render callback with kleur styling */
  onRender?: (kleur: any) => void,
  /** State change callback */
  onState?: (state: { value: boolean; aborted: boolean }) => void,
  /** Input stream */
  stdin?: NodeJS.ReadableStream,
  /** Output stream */
  stdout?: NodeJS.WritableStream
}

Usage Examples:

// Basic toggle prompt
const response = await prompts({
  type: 'toggle',
  name: 'notifications',
  message: 'Enable notifications?',
  initial: true,
  active: 'enabled',
  inactive: 'disabled'
});

// Toggle with custom labels
const response = await prompts({
  type: 'toggle',
  name: 'mode',
  message: 'Development mode?',
  initial: false,
  active: 'development',
  inactive: 'production'
});

// Toggle with formatting
const response = await prompts({
  type: 'toggle',
  name: 'privacy',
  message: 'Make profile public?',
  initial: false,
  active: 'public',
  inactive: 'private',
  format: (value, values) => ({
    isPublic: value,
    visibility: value ? 'public' : 'private',
    username: values.username
  })
});

Prompt Behavior

Confirm Prompt Controls

  • Y key: Select Yes (true)
  • N key: Select No (false)
  • Arrow keys: Navigate between Yes/No
  • Enter: Submit current selection
  • Escape: Cancel prompt

Toggle Prompt Controls

  • Arrow keys: Switch between active/inactive states
  • Tab: Switch between active/inactive states
  • Space: Switch between active/inactive states
  • Enter: Submit current state
  • Escape: Cancel prompt

Return Values

  • Confirm: Returns boolean value (true/false)
  • Toggle: Returns boolean value (true/false)

Both prompts return the boolean value directly, or the result of the format function if provided.

Visual Display

Confirm Prompt:

? Do you want to continue? › (Y/n)
? Do you want to continue? › (y/N)  // when initial: false

Toggle Prompt:

? Enable notifications? › enabled / disabled
? Development mode? › development / production

Formatting Examples

// Confirm with custom format
{
  type: 'confirm',
  name: 'terms',
  message: 'Accept terms and conditions?',
  format: value => ({
    accepted: value,
    timestamp: value ? new Date().toISOString() : null
  })
}

// Toggle with status mapping
{
  type: 'toggle', 
  name: 'feature',
  message: 'Enable beta features?',
  active: 'enabled',
  inactive: 'disabled',
  format: value => value ? 'FEATURE_ON' : 'FEATURE_OFF'
}

These prompts are ideal for:

  • User confirmations before destructive actions
  • Feature toggles and settings
  • Binary configuration options
  • Consent and agreement prompts
  • Mode selection (development/production, public/private, etc.)

Install with Tessl CLI

npx tessl i tessl/npm-prompts

docs

choice-prompts.md

confirmation-prompts.md

core-prompting.md

index.md

number-date-prompts.md

testing.md

text-prompts.md

tile.json