termino

Select

A vertical list for choosing from multiple options. Focus the select to enable keyboard input.

~/components/select — focus, ↑↓, enter
live
$ termino select-demo
New File Create a new file
Open File Open an existing file
Save Save current file
Save As… Save to a new path
────────────────────────
Exit Quit application
event focus() — awaiting keys
picked

##Renderable API

tsrenderable
1import { SelectRenderable, SelectRenderableEvents, createCliRenderer } from "@opentui/core"
2
3const renderer = await createCliRenderer()
4
5const menu = new SelectRenderable(renderer, {
6id: "menu",
7width: 30,
8height: 8,
9options: [
10 { name: "New File", description: "Create a new file" },
11 { name: "Open File", description: "Open an existing file" },
12 { name: "Save", description: "Save current file" },
13 { name: "Exit", description: "Exit the application" },
14],
15})
16
17menu.on(SelectRenderableEvents.ITEM_SELECTED, (index, option) => {
18console.log("Selected:", option.name)
19})
20
21menu.focus()
22renderer.root.add(menu)

##Construct API

tsconstruct
1import { Select, createCliRenderer } from "@opentui/core"
2
3const renderer = await createCliRenderer()
4
5const menu = Select({
6width: 30,
7height: 8,
8options: [
9 { name: "Option 1", description: "First option" },
10 { name: "Option 2", description: "Second option" },
11 { name: "Option 3", description: "Third option" },
12],
13})
14
15menu.focus()
16renderer.root.add(menu)

##Keyboard navigation

When focused, the select responds to these keys:

~/keymap
↑ / kMove selection up
↓ / jMove selection down
Shift+↑ / ↓Fast scroll (5 items)
EnterSelect current item

##Events

  • ITEM_SELECTED — fires when the user presses Enter on an option. Receives (index: number, option: SelectOption).
  • SELECTION_CHANGED — fires when the highlighted option changes. Receives (index: number, option: SelectOption).

##Option structure

ts
1interface SelectOption {
2name: string // Display text
3description: string // Displays below the name
4value?: string // Optional value
5}

Separator rows: use { name: "---", description: "" } for a visual-only separator.

##Programmatic control

ts
1menu.getSelectedIndex() // current selection index
2menu.getSelectedOption() // currently selected option
3menu.setSelectedIndex(2) // set selection programmatically
4menu.moveUp() // navigate programmatically
5menu.moveDown(3) // move down multiple items
6menu.selectCurrent() // trigger selection of current item
7
8menu.options = [
9{ name: "New Option 1", description: "First" },
10{ name: "New Option 2", description: "Second" },
11]

##Properties

properties
proptypedefaultdescription
widthnumber-Component width
heightnumber-Component height
optionsSelectOption[][]Available options
selectedIndexnumber0Initially selected index
backgroundColorstring | RGBAtransparentBackground color
textColorstring | RGBA"#FFFFFF"Normal text color
focusedBackgroundColorstring | RGBA"#1a1a1a"Background when focused
selectedBackgroundColorstring | RGBA"#334455"Selected item background
selectedTextColorstring | RGBA"#FFFF00"Selected item text color
descriptionColorstring | RGBA"#888888"Description text color
showDescriptionbooleantrueShow option descriptions
showScrollIndicatorbooleanfalseShow scroll position indicator
showSelectionIndicatorbooleantrueShow selection marker and gutter
wrapSelectionbooleanfalseWrap selection at list boundaries
itemSpacingnumber0Spacing between items
fastScrollStepnumber5Items to skip with Shift+Up/Down