▚Select
A vertical list for choosing from multiple options. Focus the select to enable keyboard input.
$ 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
1import { SelectRenderable, SelectRenderableEvents, createCliRenderer } from "@opentui/core"23const renderer = await createCliRenderer()45const 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})1617menu.on(SelectRenderableEvents.ITEM_SELECTED, (index, option) => {18console.log("Selected:", option.name)19})2021menu.focus()22renderer.root.add(menu)
##Construct API
1import { Select, createCliRenderer } from "@opentui/core"23const renderer = await createCliRenderer()45const 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})1415menu.focus()16renderer.root.add(menu)
##Keyboard navigation
When focused, the select responds to these keys:
↑ / 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
1interface SelectOption {2name: string // Display text3description: string // Displays below the name4value?: string // Optional value5}
Separator rows: use { name: "---", description: "" } for a visual-only separator.
##Programmatic control
1menu.getSelectedIndex() // current selection index2menu.getSelectedOption() // currently selected option3menu.setSelectedIndex(2) // set selection programmatically4menu.moveUp() // navigate programmatically5menu.moveDown(3) // move down multiple items6menu.selectCurrent() // trigger selection of current item78menu.options = [9{ name: "New Option 1", description: "First" },10{ name: "New Option 2", description: "Second" },11]
##Properties
properties
| prop | type | default | description |
|---|---|---|---|
| width | number | - | Component width |
| height | number | - | Component height |
| options | SelectOption[] | [] | Available options |
| selectedIndex | number | 0 | Initially selected index |
| backgroundColor | string | RGBA | transparent | Background color |
| textColor | string | RGBA | "#FFFFFF" | Normal text color |
| focusedBackgroundColor | string | RGBA | "#1a1a1a" | Background when focused |
| selectedBackgroundColor | string | RGBA | "#334455" | Selected item background |
| selectedTextColor | string | RGBA | "#FFFF00" | Selected item text color |
| descriptionColor | string | RGBA | "#888888" | Description text color |
| showDescription | boolean | true | Show option descriptions |
| showScrollIndicator | boolean | false | Show scroll position indicator |
| showSelectionIndicator | boolean | true | Show selection marker and gutter |
| wrapSelection | boolean | false | Wrap selection at list boundaries |
| itemSpacing | number | 0 | Spacing between items |
| fastScrollStep | number | 5 | Items to skip with Shift+Up/Down |