CommandHistory.load constructor
CommandHistory.load({
- required KeyValueStore kv,
- required String key,
- int maxEntries = 1000,
- String prefix = storagePrefix,
Loads the history for key from kv, returning an empty history when none
is stored yet. A corrupt or unreadable entry is treated as empty so it can
never break the shell.
Implementation
factory CommandHistory.load({
required KeyValueStore kv,
required String key,
int maxEntries = 1000,
String prefix = storagePrefix,
}) {
final storageKey = '$prefix${CommandHistoryBuffer.sanitizeKey(key)}';
final buffer = CommandHistoryBuffer(maxEntries: maxEntries);
try {
final raw = kv.read(storageKey);
if (raw != null) {
buffer.replaceAll(raw.split('\n').where((l) => l.trim().isNotEmpty));
}
} on Object {
// A corrupt or unreadable entry must never break the shell.
}
return CommandHistory._(buffer, kv, storageKey);
}