Raxol.Terminal.Commands.History (Raxol v0.5.0)
View SourceManages 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.
Updates the command history configuration. Delegates to update_size/2 for compatibility.
Updates the maximum size of the command history. Truncates the history if needed.
Types
@type command_history() :: [String.t()]
@type command_history_config() :: %{ max_size: non_neg_integer(), current_input: String.t() }
@type t() :: %Raxol.Terminal.Commands.History{ commands: command_history(), current_index: integer(), current_input: String.t(), max_size: non_neg_integer() }
Functions
Adds a command to the history.
Examples
iex> history = History.new(1000)
iex> history = History.add(history, "ls -la")
iex> history.commands
["ls -la"]
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
[]
@spec list(t()) :: command_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"]
@spec maybe_add_to_history(Emulator.t(), integer()) :: Emulator.t()
@spec maybe_add_to_history(Emulator.t(), integer()) :: Emulator.t()
@spec maybe_add_to_history(Emulator.t(), any()) :: Emulator.t()
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.
@spec new(non_neg_integer()) :: t()
Creates a new command history manager.
Examples
iex> history = History.new(1000)
iex> history.max_size
1000
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{...}}
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{...}}
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"
Updates the command history configuration. Delegates to update_size/2 for compatibility.
@spec update_size(t(), non_neg_integer()) :: t()
Updates the maximum size of the command history. Truncates the history if needed.