Skip to content

Input

extends Element

Input: single-line text input with cursor, horizontal scrolling and placeholder. Fires "change" while typing and "enter" on return.

Properties

PropertyTypeDefaultDescription
textstring""Current input value (rawString: typed braces stay literal text)
placeholderstring""shown while empty and unfocused
placeholderColornumbercolors.grayColor of the placeholder text
maxLengthnumber|falsefalsemaximum text length, false = unlimited
replaceCharstring|falsefalsee.g. "*" for password fields
patternstring|falsefalseLua pattern each char must match
widthnumber12Width in terminal cells
heightnumber1Height in terminal cells
backgroundnumber|falsecolors.lightGrayBackground color (false = transparent)
foregroundnumbercolors.blackText color

Events

EventRegistrarDescription
change:onChange(fn)Fired after every text edit with the new text
enter:onEnter(fn)Fired on the enter key with the current text

Methods

Input:setup()

Initializes per-instance state and input handlers.

Input:handleKey(event, a, b)

Handles typing, paste and editing keys while focused.

  • event (string) The key event name (key, key_up, char, paste)
  • a (any) Key code or typed/pasted text
  • b (any, optional) Secondary key-event value

Input:render(buf)

Renders the text (or placeholder) and requests the cursor while focused.

  • buf (Render) The render buffer

Input:measure()

Intrinsic size for basalt.auto(): longest of text/placeholder x 1.

  • returns width (number) The measured width
  • returns height (number) The measured height

Last updated:

Released under the MIT License.