up method
Moves to the previous (older) entry matching the active prefix, returning
the line to show or null to leave the current line unchanged.
On the first step from a fresh line it captures line (to restore on the
way back down) and prefix (the text before the cursor — empty browses
every entry); both are supplied by the caller so prefix computation can
respect the host's own character model.
Implementation
String? up({required String line, required String prefix}) {
final entries = _history.entries;
if (_index == 0) return null;
if (_index == entries.length) {
_stash = line;
_searchPrefix = prefix;
}
final active = _searchPrefix ?? '';
for (var i = _index - 1; i >= 0; i--) {
if (entries[i].startsWith(active)) {
_index = i;
return entries[i];
}
}
// No earlier entry matches the prefix: keep the current line.
return null;
}