Raxol.Terminal.Input (Raxol v0.4.0)

View Source

Terminal input module.

This module handles keyboard and mouse input events for the terminal, including:

  • Input buffering
  • Mode management
  • Input history
  • Special key handling

Summary

Functions

Adds a command to the history.

Clears the input buffer.

Example completion callback: completes common Elixir keywords.

Gets the current input buffer.

Gets the input mode.

Creates a new input handler.

Gets the next command from history.

Gets the previous command from history.

Processes a keyboard event.

Processes a mouse event.

Sets a callback function for context-aware tab completion. The callback receives the current buffer and returns a list of completion options.

Sets the input mode.

Triggers or cycles tab completion. If a callback is set, cycles through options; otherwise, inserts spaces.

Types

t()

@type t() :: %Raxol.Terminal.Input{
  buffer: String.t(),
  history: [String.t()],
  history_index: non_neg_integer(),
  history_limit: non_neg_integer(),
  mode: atom()
}

Functions

add_to_history(input, command)

Adds a command to the history.

Examples

iex> input = Input.new()
iex> input = Input.add_to_history(input, "test")
iex> length(input.history)
1

clear_buffer(input)

Clears the input buffer.

Examples

iex> input = Input.new()
iex> input = Input.process_keyboard(input, "test")
iex> input = Input.clear_buffer(input)
iex> Input.get_buffer(input)
""

example_completion_callback(buffer)

Example completion callback: completes common Elixir keywords.

get_buffer(input)

Gets the current input buffer.

Examples

iex> input = Input.new()
iex> input = Input.process_keyboard(input, "test")
iex> Input.get_buffer(input)
"test"

get_mode(input)

Gets the input mode.

Examples

iex> input = Input.new()
iex> Input.get_mode(input)
:normal

handle_backspace(input)

handle_click(input, x, y, button)

handle_drag(input, x, y, button)

handle_enter(input)

handle_escape(input)

handle_printable(input, char)

handle_release(input, x, y, button)

handle_tab(input)

new(history_limit \\ 100)

Creates a new input handler.

Examples

iex> input = Input.new()
iex> input.mode
:normal
iex> input.buffer
""

next_command(input)

Gets the next command from history.

Examples

iex> input = Input.new()
iex> input = Input.add_to_history(input, "test")
iex> input = Input.previous_command(input)
iex> input = Input.next_command(input)
iex> input.buffer
""

previous_command(input)

Gets the previous command from history.

Examples

iex> input = Input.new()
iex> input = Input.add_to_history(input, "test")
iex> input = Input.previous_command(input)
iex> input.buffer
"test"

process_keyboard(input, key)

Processes a keyboard event.

Examples

iex> input = Input.new()
iex> input = Input.process_keyboard(input, "a")
iex> input.buffer
"a"

process_mouse(input, event)

Processes a mouse event.

Examples

iex> input = Input.new()
iex> input = Input.process_mouse(input, {:click, 1, 2, 1})
iex> input.buffer
""

set_completion_callback(input, callback)

Sets a callback function for context-aware tab completion. The callback receives the current buffer and returns a list of completion options.

set_mode(input, mode)

Sets the input mode.

Examples

iex> input = Input.new()
iex> input = Input.set_mode(input, :insert)
iex> input.mode
:insert

tab_complete(input)

Triggers or cycles tab completion. If a callback is set, cycles through options; otherwise, inserts spaces.