termprompt

select

Pick one option from a list.

Preview

Active state

select
Pick a framework
Next.js (React SSR)
○ Hono
○ Astro

After submit

select
Pick a framework
Next.js

Usage

import { select, isCancel } from 'termprompt';

const framework = await select({
  message: 'Pick a framework',
  options: [
    { value: 'next', label: 'Next.js', hint: 'React SSR' },
    { value: 'hono', label: 'Hono', hint: 'Edge-first' },
    { value: 'astro', label: 'Astro', hint: 'Content sites' },
  ],
});

if (isCancel(framework)) process.exit(0);
console.log(framework); // 'next' | 'hono' | 'astro'

Props

PropTypeDefaultDescription
messagestringrequiredQuestion text
optionsOption<T>[]requiredList of choices
initialValueTfirst optionPre-selected value
maxItemsnumber10Visible items before scrolling

Option

FieldTypeDescription
valueTThe value returned on selection
labelstringDisplay text
hintstring?Gray text shown next to the active option
disabledboolean?Grayed out, cannot be selected

Disabled Options

const db = await select({
  message: 'Database',
  options: [
    { value: 'pg', label: 'PostgreSQL' },
    { value: 'mysql', label: 'MySQL', disabled: true },
    { value: 'sqlite', label: 'SQLite' },
  ],
});
disabled option
Database
PostgreSQL
MySQL (disabled)
○ SQLite

Keyboard

KeyAction
Up / kMove up
Down / jMove down
EnterSubmit
EscCancel

Scrolling

When the list is longer than maxItems, the viewport scrolls automatically. Ellipsis indicators appear at the top or bottom when more items exist.

On this page