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
| Prop | Type | Default | Description |
|---|---|---|---|
message | string | required | Question text |
options | Option<T>[] | required | List of choices |
initialValue | T | first option | Pre-selected value |
maxItems | number | 10 | Visible items before scrolling |
Option
| Field | Type | Description |
|---|---|---|
value | T | The value returned on selection |
label | string | Display text |
hint | string? | Gray text shown next to the active option |
disabled | boolean? | 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
| Key | Action |
|---|---|
Up / k | Move up |
Down / j | Move down |
Enter | Submit |
Esc | Cancel |
Scrolling
When the list is longer than maxItems, the viewport scrolls automatically. Ellipsis indicators appear at the top or bottom when more items exist.