term.input

index · term

Overview

Full-featured line input with multi-line editing, history, completion, and Kitty keyboard protocol support.

Submodules

ModuleDescription
term.input.completionCompletion engine with pluggable sources and candidate management.
term.input.historyCommand history with persistent storage, navigation, and duplicate filtering.
term.input.promptInput prompt display with optional configurable blocks.
term.input.rendererCompletion renderer interface and built-in inline ghost renderer.

Functions

NameSignature
input:eventinput:event() -> action, combo
input:runinput:run(exit_events) -> event, combo
input:newlineinput:newline() -> redraw
input:clear_allinput:clear_all()
input:clear_from_promptinput:clear_from_prompt()
input:full_redrawinput:full_redraw() -> redraw
input:move_rightinput:move_right() -> redraw
input:move_leftinput:move_left() -> redraw
input:move_to_previous_spaceinput:move_to_previous_space() -> redraw
input:move_to_next_spaceinput:move_to_next_space() -> redraw
input:insertinput:insert(char) -> redraw
input:backspaceinput:backspace() -> redraw
input:scroll_completioninput:scroll_completion(direction) -> redraw
input:promote_completion_fullinput:promote_completion_full() -> redraw
input:promote_completioninput:promote_completion() -> redraw
input:search_completioninput:search_completion() -> redraw
input:external_editorinput:external_editor()
input:insert_last_arginput:insert_last_arg() -> redraw
input:copy_to_clipboardinput:copy_to_clipboard() -> success
input:displayinput:display(force)
input:buffer_emptyinput:buffer_empty() -> empty
input:prompt_leninput:prompt_len() -> len, prompt
input:max_widthinput:max_width() -> width
input:relocateinput:relocate()
newnew(config) -> input

input:event() -> action, combo

Process a single keyboard event and return the action taken

Reads one key event via KKBP, handles character insertion, cursor movement, history navigation, and completion. Returns true when a redraw is needed, an event string like "execute" or "exit" for terminal events, or nil when no action was taken.

input:run(exit_events) -> event, combo

Run the input event loop until an exit event occurs

Loops calling event() and display(), handling terminal resizes. The exit_events table maps event names to true (defaults to {execute = true, exit = true}). Returns the triggering event name.

input:newline() -> redraw

Insert a new line at the cursor position

input:clear_all()

Clear the entire input area and reset cursor to start

input:clear_from_prompt()

Clear the input area from the end of the prompt onward

input:full_redraw() -> redraw

Perform a complete redraw of the prompt and input content

input:move_right() -> redraw

Move cursor one position to the right or to the next line

input:move_left() -> redraw

Move cursor one position to the left or to the previous line

input:move_to_previous_space() -> redraw

Move cursor back to the previous space character

input:move_to_next_space() -> redraw

Move cursor forward to the next space character

input:insert(char) -> redraw

Insert a character at the current cursor position

input:backspace() -> redraw

Delete the character before the cursor

input:scroll_completion(direction) -> redraw

Scroll through completion candidates in the given direction

input:promote_completion_full() -> redraw

Accept the currently selected completion candidate in full

input:promote_completion() -> redraw

Promote completion to common prefix or accept if single candidate

Two-phase promotion logic. With a single candidate, or when the provider signals should_promote_full(), delegates to promote_completion_full(). With multiple candidates, appends the longest common prefix to the input and re-runs the completion search.

input:search_completion() -> redraw

Trigger a completion search based on current input content

When cfg.eol_only is true (the default), only searches when the cursor is at end-of-line and the current line does not end with whitespace. When false, searches at any cursor position and passes the cursor position to the provider. Delegates to completion:search() with the current line and history object.

input:external_editor()

Open the current input content in an external editor

input:insert_last_arg() -> redraw

Insert the last argument from the previous history command

input:copy_to_clipboard() -> success

Copy current input content to clipboard using OSC52

input:display(force)

Decide between full and partial redraw and render accordingly

input:buffer_empty() -> empty

Check whether the input buffer contains no text

input:prompt_len() -> len, prompt

Return the display length and rendered prompt string

input:max_width() -> width

Return the maximum editable width in columns

input:relocate()

Find the input's row again after a resize, and erase from it down

For an input in the scrolling screen, the relocate config key. Call it after update_window_size and before the redraw. A terminal that rewraps its lines on a resize, as foot and alacritty do, moves the input's line and carries the cursor with it. The method asks the terminal where the cursor went (CPR), then counts back the rows the rewrap put above it. It sets cfg.l to the line's first row and erases from there to the screen's end. One prompt then stands, and the output above stays.

The cursor's column at the last draw says how many rows the rewrap put above it. A terminal that cuts its lines instead, as xterm does, clamps the cursor to the last column. When the old column is a multiple of the new width, both answer the same column, and the method takes the rewrap. With no answer to the query, cfg.l is clamped to the screen's height and nothing is erased.

Kitty 0.41 does not carry the cursor on a full screen: the rewrap scrolls the line up and leaves the cursor on the bottom row. The method then finds the line's last row, and the rows above it keep the old prompt.

new(config) -> input

Create a new input instance

The config table may contain: