Overview
TheInput widget provides single-line text entry with cursor management and optional password masking. It handles basic text editing operations and emits events for user input.
Constructor
InputOptions
Width of the input field. Accepts:
- Number: fixed width in cells
- String: percentage (e.g.,
"50%") or"auto"
Height of the input field. Typically set to 1 or 3 (with border).
Maximum number of characters allowed. No limit if not specified.
Character to display instead of actual input (for password fields).Example:
"*" or "•"Foreground (text) color. Accepts:
- Hex string:
"#FF0000" - Color name:
"red","blue", etc. - 256-color code:
196
Background color. Same format as
fg.Border style. Valid values:
"none"- no border"single"- single-line border"double"- double-line border"rounded"- rounded corners"bold"- bold border
Methods
getValue()
Get the current input value.The current text content of the input field.
ts/src/widgets/input.ts:32
getCursor()
Get the current cursor position.Zero-based cursor position (character index).
ts/src/widgets/input.ts:43
setCursor()
Set the cursor position.Zero-based cursor position. Will be clamped to valid range
[0, length].ts/src/widgets/input.ts:49
setMaxLength()
Set the maximum input length.Maximum number of characters allowed. Use
0 for unlimited.ts/src/widgets/input.ts:53
setMask()
Enable password masking with a specific character.Character to display instead of actual input (e.g.,
"*", "•").Only the first character of the string is used.ts/src/widgets/input.ts:57
clearMask()
Disable password masking, showing actual input characters.ts/src/widgets/input.ts:62
Examples
Inherited Methods
Input inherits all methods from the Widget base class, including:setVisible(visible)- Control visibilitysetForeground(color)- Set text colorsetBackground(color)- Set background colorsetBorderStyle(style)- Change border styledestroy()- Clean up resources
Event Handling
Input widgets respond to keyboard events:- Key events - Character input, backspace, delete
- Navigation - Left/right arrows, home/end
- Selection - Ctrl+A to select all (platform-dependent)
app.drainEvents() in your event loop.
Notes
- Input is a single-line text field (use TextArea for multi-line)
- Cursor position is automatically clamped to valid range
- Password masking only affects display, not the actual stored value
- Maximum length is enforced by the native layer
- Input widgets cannot have children