termprompt

search

Type-to-filter select prompt.

Preview

Filtering

search
Select timezone
pac
Pacific (UTC-8)
○ Asia/Pacific

After submit

search
Select timezone
Pacific

Usage

import { search, isCancel } from 'termprompt';

const timezone = await search({
  message: 'Select timezone',
  options: [
    { value: 'utc', label: 'UTC' },
    { value: 'est', label: 'Eastern', hint: 'UTC-5' },
    { value: 'pst', label: 'Pacific', hint: 'UTC-8' },
    { value: 'cet', label: 'Central European', hint: 'UTC+1' },
    { value: 'jst', label: 'Japan', hint: 'UTC+9' },
  ],
});

if (isCancel(timezone)) process.exit(0);
console.log(timezone);

Props

PropTypeDefaultDescription
messagestringrequiredQuestion text
optionsSearchOption<T>[]requiredFull list to filter from
placeholderstring?noneGray text when query is empty
maxItemsnumber10Visible results before scrolling

SearchOption

FieldTypeDescription
valueTValue returned on selection
labelstringSearchable display text
hintstring?Also searchable, shown on active

How Filtering Works

Case-insensitive search against both label and hint. Results update on every keystroke and the cursor resets to the first match.

Keyboard

KeyAction
TypeFilter options
Up / DownNavigate results
BackspaceEdit query
EnterSubmit
EscCancel

On this page