Class History

java.lang.Object
org.aesh.readline.history.History
Direct Known Subclasses:
InMemoryHistory

public abstract class History extends Object
Abstract base class for managing command line history.
Author:
Ståle W. Pedersen
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Protected constructor for subclasses.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Clears all entries from the history.
    void
    Disables history tracking.
    void
    Enables history tracking.
    abstract int[]
    find(int[] search)
    Finds an entry in the history that matches the search.
    abstract int[]
    get(int index)
    Gets the history entry at the specified index.
    abstract List<int[]>
    Gets all entries in the history.
    abstract int[]
    Gets the current line being edited.
    Returns the current ignore patterns.
    Gets the current search direction.
    Gets the timestamps (epoch millis) for all entries in the history.
    boolean
    Checks if history is enabled.
    abstract Optional<int[]>
    Fetch the next history entry.
    abstract Optional<int[]>
    Fetch the previous history entry.
    abstract void
    push(int[] entry)
    Pushes a new entry to the history.
    abstract int[]
    search(int[] search)
    Searches for an entry in the history that contains the search pattern.
    abstract void
    setCurrent(int[] line)
    Sets the current line being edited (used for history navigation).
    void
    Sets patterns for commands that should not be saved to history.
    abstract void
    Sets the search direction for history searches.
    protected boolean
    Checks if a command matches any of the ignore patterns.
    abstract int
    Returns the number of entries in the history.
    abstract void
    Stops the history and performs any necessary cleanup (e.g., saving to file).

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • History

      protected History()
      Protected constructor for subclasses.
  • Method Details

    • isEnabled

      public boolean isEnabled()
      Checks if history is enabled.
      Returns:
      true if history is enabled, false otherwise
    • enable

      public void enable()
      Enables history tracking.
    • disable

      public void disable()
      Disables history tracking.
    • setIgnorePatterns

      public void setIgnorePatterns(List<String> patterns)
      Sets patterns for commands that should not be saved to history.

      Patterns support simple wildcards:

      • " *" — matches commands starting with a space (common shell convention for private commands)
      • "*password*" — matches commands containing "password" anywhere
      • "exit" — matches the exact command "exit"
      Parameters:
      patterns - the list of patterns to ignore, or null to clear
    • getIgnorePatterns

      public List<String> getIgnorePatterns()
      Returns the current ignore patterns.
      Returns:
      the ignore patterns, or null if none are set
    • shouldIgnore

      protected boolean shouldIgnore(String entry)
      Checks if a command matches any of the ignore patterns.
      Parameters:
      entry - the command string to check
      Returns:
      true if the entry should be ignored (not saved to history)
    • push

      public abstract void push(int[] entry)
      Pushes a new entry to the history.
      Parameters:
      entry - the entry to add
    • find

      public abstract int[] find(int[] search)
      Finds an entry in the history that matches the search.
      Parameters:
      search - the search pattern
      Returns:
      the matching entry, or null if not found
    • get

      public abstract int[] get(int index)
      Gets the history entry at the specified index.
      Parameters:
      index - the index of the entry to retrieve
      Returns:
      the history entry at the specified index
    • size

      public abstract int size()
      Returns the number of entries in the history.
      Returns:
      the size of the history
    • setSearchDirection

      public abstract void setSearchDirection(SearchDirection direction)
      Sets the search direction for history searches.
      Parameters:
      direction - the search direction
    • getSearchDirection

      public abstract SearchDirection getSearchDirection()
      Gets the current search direction.
      Returns:
      the current search direction
    • nextFetch

      public abstract Optional<int[]> nextFetch()
      Fetch the next history entry.
      Returns:
      an Optional containing the next history entry, or empty if at the end
    • previousFetch

      public abstract Optional<int[]> previousFetch()
      Fetch the previous history entry.
      Returns:
      an Optional containing the previous history entry, or empty if at the start
    • search

      public abstract int[] search(int[] search)
      Searches for an entry in the history that contains the search pattern.
      Parameters:
      search - the search pattern
      Returns:
      the matching entry, or null if not found
    • setCurrent

      public abstract void setCurrent(int[] line)
      Sets the current line being edited (used for history navigation).
      Parameters:
      line - the current line
    • getCurrent

      public abstract int[] getCurrent()
      Gets the current line being edited.
      Returns:
      the current line
    • getAll

      public abstract List<int[]> getAll()
      Gets all entries in the history.
      Returns:
      a list of all history entries
    • getTimestamps

      public List<Long> getTimestamps()
      Gets the timestamps (epoch millis) for all entries in the history. The returned list is parallel to getAll() — same size and order.

      The default implementation returns null, indicating timestamps are not available.

      Returns:
      a list of timestamps, or null if timestamps are not tracked
    • clear

      public abstract void clear()
      Clears all entries from the history.
    • stop

      public abstract void stop()
      Stops the history and performs any necessary cleanup (e.g., saving to file).