pub struct InputHistory { /* private fields */ }Expand description
A bounded, command-line style entry-recall buffer for TextInput.
This is the shell “type a command, press Enter, later press Up to get it
back” facility, deliberately not built on the runtime’s undo
HistoryManager: recall is a list of
submitted strings with a single recall cursor, whereas undo is a stack of
reversible edit commands. The two are complementary — undo walks the edits
within one line, recall walks between previously submitted lines.
Semantics match a typical shell with ignoredups:
pushrecords a non-empty value, skipping a run of an identical value, evicting the oldest once capacity is exceeded, and ending any recall.recall_older(Up) stores the in-progress draft on first use, then walks toward older entries, stopping at the oldest.recall_newer(Down) walks toward newer entries and, once past the newest, restores the saved draft and ends recall.- Editing the value ends recall (the edited text becomes the new draft).
Implementations§
Source§impl InputHistory
impl InputHistory
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
A new empty history retaining up to capacity entries (clamped to at
least 1).
Sourcepub fn push(&mut self, value: String)
pub fn push(&mut self, value: String)
Record a submitted value. Empty values and a value equal to the most
recent entry are not stored (ignoredups); the oldest entry is evicted
once capacity is exceeded. Either way, any active recall ends.
Sourcepub fn recall_older(&mut self, current: &str) -> Option<String>
pub fn recall_older(&mut self, current: &str) -> Option<String>
Recall the previous (older) entry, saving current as the draft on the
first step. Returns the entry to display, or None when there is
nothing to recall. Stops at the oldest entry.
Sourcepub fn recall_newer(&mut self) -> Option<String>
pub fn recall_newer(&mut self) -> Option<String>
Recall the next (newer) entry. Once past the newest entry, restores the
saved draft and ends recall. Returns None when no recall is active.
Trait Implementations§
Source§impl Clone for InputHistory
impl Clone for InputHistory
Source§fn clone(&self) -> InputHistory
fn clone(&self) -> InputHistory
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more