Raxol.Terminal.Commands.History (Raxol v0.4.0)

View Source

Manages command history for the terminal emulator.

This module provides functionality for:

  • Storing and retrieving command history
  • Navigating through command history
  • Persisting command history
  • Managing history size limits

Summary

Functions

Adds a command to the history.

Clears the command history.

Returns the current command history as a list.

Adds to the emulator's command history if the input is a newline (10), or appends to the current command buffer if it's a printable character. Returns the updated emulator struct.

Creates a new command history manager.

Retrieves the next command in history.

Retrieves the previous command in history.

Saves the current input state.

Types

t()

@type t() :: %Raxol.Terminal.Commands.History{
  commands: [String.t()],
  current_index: integer(),
  current_input: String.t(),
  max_size: non_neg_integer()
}

Functions

add(history, command)

Adds a command to the history.

Examples

iex> history = History.new(1000)
iex> history = History.add(history, "ls -la")
iex> history.commands
["ls -la"]

clear(history)

Clears the command history.

Examples

iex> history = History.new(1000)
iex> history = History.add(history, "ls -la")
iex> history = History.clear(history)
iex> history.commands
[]

list(history)

Returns the current command history as a list.

Examples

iex> history = History.new(1000)
iex> history = History.add(history, "ls -la")
iex> history = History.add(history, "cd /tmp")
iex> History.list(history)
["cd /tmp", "ls -la"]

maybe_add_to_history(emulator, char)

Adds to the emulator's command history if the input is a newline (10), or appends to the current command buffer if it's a printable character. Returns the updated emulator struct.

new(max_size)

Creates a new command history manager.

Examples

iex> history = History.new(1000)
iex> history.max_size
1000

next(history)

Retrieves the next command in history.

Examples

iex> history = History.new(1000)
iex> history = History.add(history, "ls -la")
iex> history = History.add(history, "cd /tmp")
iex> {_, history} = History.previous(history)
iex> History.next(history)
{"ls -la", %History{...}}

previous(history)

Retrieves the previous command in history.

Examples

iex> history = History.new(1000)
iex> history = History.add(history, "ls -la")
iex> history = History.add(history, "cd /tmp")
iex> History.previous(history)
{"cd /tmp", %History{...}}

save_input(history, input)

Saves the current input state.

Examples

iex> history = History.new(1000)
iex> history = History.save_input(history, "ls -l")
iex> history.current_input
"ls -l"