pub struct TerminalScrollback { /* private fields */ }Expand description
Oldest-to-newest bounded terminal scrollback.
Normal mutation retains at most limit lines. Derived deserialization stores
private fields verbatim and can bypass that relationship until the next
Self::push or Self::replace_lines.
§Examples
use ailloli_ui_terminal_core::TerminalScrollback;
let history = TerminalScrollback::new(100);
assert_eq!((history.limit(), history.len(), history.total_pushed()), (100, 0, 0));Implementations§
Source§impl TerminalScrollback
impl TerminalScrollback
Sourcepub fn new(limit: usize) -> Self
pub fn new(limit: usize) -> Self
Creates empty history with an exact retained-line limit.
A zero limit still counts later pushes but retains no lines.
§Examples
use ailloli_ui_terminal_core::TerminalScrollback;
assert_eq!(TerminalScrollback::new(0).limit(), 0);Sourcepub fn limit(&self) -> usize
pub fn limit(&self) -> usize
Returns the configured maximum retained line count.
§Examples
use ailloli_ui_terminal_core::TerminalScrollback;
assert_eq!(TerminalScrollback::new(7).limit(), 7);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the current retained line count.
§Examples
use ailloli_ui_terminal_core::TerminalScrollback;
assert_eq!(TerminalScrollback::default().len(), 0);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether no history lines are retained.
§Examples
use ailloli_ui_terminal_core::TerminalScrollback;
assert!(TerminalScrollback::default().is_empty());Sourcepub fn iter(&self) -> impl Iterator<Item = &TerminalLine>
pub fn iter(&self) -> impl Iterator<Item = &TerminalLine>
Iterates retained lines from oldest to newest.
§Examples
use ailloli_ui_terminal_core::{TerminalLine, TerminalScrollback, TerminalStyle};
let mut history = TerminalScrollback::new(1);
history.push(TerminalLine::blank(2, TerminalStyle::default()));
assert_eq!(history.iter().count(), 1);Sourcepub fn total_pushed(&self) -> u64
pub fn total_pushed(&self) -> u64
Returns the saturating cumulative push count.
Clearing retained lines does not reset this counter. Self::replace_lines
can explicitly replace it with any u64.
§Examples
use ailloli_ui_terminal_core::{TerminalLine, TerminalScrollback, TerminalStyle};
let mut history = TerminalScrollback::new(0);
history.push(TerminalLine::blank(1, TerminalStyle::default()));
assert_eq!((history.len(), history.total_pushed()), (0, 1));Sourcepub fn replace_lines(
&mut self,
lines: impl IntoIterator<Item = TerminalLine>,
total_pushed: u64,
)
pub fn replace_lines( &mut self, lines: impl IntoIterator<Item = TerminalLine>, total_pushed: u64, )
Replaces retained lines and the cumulative push counter.
Input is consumed oldest-to-newest; if it exceeds the limit, only the
newest limit lines remain. A zero limit consumes the supplied iterator
only up to construction of the iterator and retains none. total_pushed
is accepted verbatim and need not equal the input/retained count.
§Examples
use ailloli_ui_terminal_core::{TerminalLine, TerminalScrollback, TerminalStyle};
let style = TerminalStyle::default();
let mut history = TerminalScrollback::new(1);
history.replace_lines([TerminalLine::blank(1, style), TerminalLine::blank(2, style)], 9);
assert_eq!((history.len(), history.iter().next().unwrap().len(), history.total_pushed()), (1, 2, 9));Sourcepub fn push(&mut self, line: TerminalLine)
pub fn push(&mut self, line: TerminalLine)
Counts and appends one line, evicting oldest lines above the limit.
total_pushed saturates at u64::MAX. A zero limit increments the
counter but retains no line.
§Examples
use ailloli_ui_terminal_core::{TerminalLine, TerminalScrollback, TerminalStyle};
let mut history = TerminalScrollback::new(1);
history.push(TerminalLine::blank(1, TerminalStyle::default()));
history.push(TerminalLine::blank(2, TerminalStyle::default()));
assert_eq!((history.len(), history.total_pushed()), (1, 2));Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Removes retained lines without changing the limit or cumulative count.
§Examples
use ailloli_ui_terminal_core::{TerminalLine, TerminalScrollback, TerminalStyle};
let mut history = TerminalScrollback::new(1);
history.push(TerminalLine::blank(1, TerminalStyle::default())); history.clear();
assert!(history.is_empty() && history.total_pushed() == 1);Trait Implementations§
Source§impl Clone for TerminalScrollback
impl Clone for TerminalScrollback
Source§fn clone(&self) -> TerminalScrollback
fn clone(&self) -> TerminalScrollback
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more