Struct TerminalScrollback

Source
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

Source

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);
Source

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);
Source

pub fn len(&self) -> usize

Returns the current retained line count.

§Examples
use ailloli_ui_terminal_core::TerminalScrollback;
assert_eq!(TerminalScrollback::default().len(), 0);
Source

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());
Source

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);
Source

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));
Source

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));
Source

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));
Source

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

Source§

fn clone(&self) -> TerminalScrollback

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TerminalScrollback

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TerminalScrollback

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for TerminalScrollback

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for TerminalScrollback

Source§

fn eq(&self, other: &TerminalScrollback) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for TerminalScrollback

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for TerminalScrollback

Source§

impl StructuralPartialEq for TerminalScrollback

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,