Class DefaultHistory

java.lang.Object
org.jline.reader.impl.history.DefaultHistory
All Implemented Interfaces:
Iterable<History.Entry>, History

public class DefaultHistory extends Object implements History
Default implementation of History with file-based persistent storage.

This class provides a complete implementation of the History interface with the following features:

  • In-memory storage of history entries with configurable size limits
  • Persistent storage in a text file with configurable location and size limits
  • Support for timestamped history entries
  • Filtering of entries based on patterns defined in the LineReader.HISTORY_IGNORE variable
  • Options to ignore duplicates, reduce blanks, and ignore commands starting with spaces
  • Incremental saving of history entries
  • History navigation (previous/next, first/last, etc.)

The history file format is either plain text with one command per line, or if LineReader.Option.HISTORY_TIMESTAMPED is set, each line starts with a timestamp in milliseconds since epoch, followed by a colon and the command text.

Applications using this class should install a shutdown hook to call save() to ensure history is saved to disk when the application exits.

Example usage:

 LineReader reader = LineReaderBuilder.builder()
     .variable(LineReader.HISTORY_FILE, Paths.get(System.getProperty("user.home"), ".myapp_history"))
     .build();
 // History is automatically attached to the reader

 // To save history manually:
 ((DefaultHistory) reader.getHistory()).save();
 
See Also: