▚Input
Text input field with cursor, placeholder text, and focus states. Focus the input to receive keyboard input.
$ termino input-demo — focus me and type
name enter your name…
username opentui_dev
events awaiting input…
chars 0 enter/submit disabled
##Renderable API
1import { InputRenderable, InputRenderableEvents, createCliRenderer } from "@opentui/core"23const renderer = await createCliRenderer()45const input = new InputRenderable(renderer, {6id: "name-input",7width: 25,8placeholder: "Enter your name...",9})1011input.on(InputRenderableEvents.CHANGE, (value) => {12console.log("Input value:", value)13})1415input.focus()16renderer.root.add(input)
##Construct API
1import { Input, createCliRenderer } from "@opentui/core"23const renderer = await createCliRenderer()45const input = Input({6placeholder: "Enter your name...",7width: 25,8})910input.focus()11renderer.root.add(input)
##Focus states
The CHANGE event is emitted after text insertion and deletion operations, and when assigning a different value. The listener receives the current value.
##Password fields
Style an input as a password field with a masked value:
1const passwordInput = Input({2id: "password-input",3width: 20,4placeholder: "••••••••",5backgroundColor: "#222",6focusedBackgroundColor: "#333",7textColor: "#FFF",8cursorColor: "#0F0",9})1011const mask = (value: string) => "•".repeat(value.length)1213// Hook into change events to render the masked value14passwordInput.on("change", (value) => {15console.log("typed:", value)16})
##Tab navigation
Add tab navigation between multiple inputs:
1const inputs = [usernameInput, passwordInput]2let focusIndex = 034renderer.keyInput.on("keypress", (key) => {5if (key.name === "tab") {6 focusIndex = (focusIndex + 1) % inputs.length7 inputs[focusIndex].focus()8}9})
##Key bindings
TabMove focus to next input
Shift+TabMove focus to previous input
BackspaceDelete previous character
EnterSubmit (respects minLength)
Home / EndJump to start / end
Ctrl+UClear input
##Properties
properties
| prop | type | default | description |
|---|---|---|---|
| width | number | "auto" | "{n}%" | "auto" | Input field width |
| value | string | "" | Initial text value |
| placeholder | string | "" | Placeholder text when empty |
| minLength | number | 0 | Minimum UTF-16 length required for submit |
| maxLength | number | 1000 | Maximum UTF-16 length |
| backgroundColor | string | RGBA | transparent | Background when unfocused |
| focusedBackgroundColor | string | RGBA | transparent | Background when focused |
| textColor | string | RGBA | "#FFFFFF" | Text color |
| cursorColor | string | RGBA | "#FFFFFF" | Cursor color |
| position | "relative" | "absolute" | "relative" | Effective positioning mode |