Raxol.Terminal.HistoryBuffer (Raxol v2.0.1)

View Source

Manages terminal command history buffer operations. This module handles the storage and retrieval of command history.

Summary

Functions

Adds a command to the history buffer.

Clears the command history.

Gets all commands in history.

Gets the command at the specified index.

Gets the maximum history size.

Gets the current history position.

Gets the history size.

Loads history from a file.

Creates a new history buffer with the specified maximum size.

Moves to the next command in history.

Moves to the previous command in history.

Saves the history to a file.

Sets the maximum history size.

Sets the history position.

Types

t()

@type t() :: %Raxol.Terminal.HistoryBuffer{
  commands: [String.t()],
  max_size: non_neg_integer(),
  position: integer()
}

Functions

add_command(buffer, command)

@spec add_command(t(), String.t()) :: t()

Adds a command to the history buffer.

clear(buffer)

@spec clear(t()) :: t()

Clears the command history.

get_all_commands(buffer)

@spec get_all_commands(t()) :: [String.t()]

Gets all commands in history.

get_command_at(buffer, index)

@spec get_command_at(t(), integer()) :: {:ok, String.t()} | {:error, String.t()}

Gets the command at the specified index.

get_max_size(buffer)

@spec get_max_size(t()) :: non_neg_integer()

Gets the maximum history size.

get_position(buffer)

@spec get_position(t()) :: integer()

Gets the current history position.

get_size(buffer)

@spec get_size(t()) :: non_neg_integer()

Gets the history size.

load_from_file(buffer, file_path)

@spec load_from_file(t(), String.t()) :: {:ok, t()} | {:error, String.t()}

Loads history from a file.

new(max_size \\ 1000)

@spec new(non_neg_integer()) :: t()

Creates a new history buffer with the specified maximum size.

next_command(buffer)

@spec next_command(t()) :: {:ok, t(), String.t()} | {:error, String.t()}

Moves to the next command in history.

previous_command(buffer)

@spec previous_command(t()) :: {:ok, t(), String.t()} | {:error, String.t()}

Moves to the previous command in history.

save_to_file(buffer, file_path)

@spec save_to_file(t(), String.t()) :: :ok | {:error, String.t()}

Saves the history to a file.

set_max_size(buffer, max_size)

@spec set_max_size(t(), non_neg_integer()) :: t()

Sets the maximum history size.

set_position(buffer, position)

@spec set_position(t(), integer()) :: t()

Sets the history position.