Raxol.Terminal.Commands.History (Raxol v0.4.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.
Types
@type t() :: %Raxol.Terminal.Commands.History{ commands: [String.t()], 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
[]
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"]
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.
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"