Struct TerminalEventLog

Source
pub struct TerminalEventLog {
    pub limit: usize,
    pub next_sequence: u64,
    pub records: Vec<TerminalEventRecord>,
}
Expand description

Bounded, insertion-ordered log of sanitized terminal events.

Recording sanitizes each event immediately using the supplied snapshot configuration. Retention keeps the newest limit records; a zero limit stores none but still allocates and returns sequence numbers. Public fields and deserialization can violate capacity and sequence assumptions.

§Examples

use ailloli_ui_terminal_core::{TerminalEventLog, TerminalSnapshotConfig};

let mut log = TerminalEventLog::new(1);
let config = TerminalSnapshotConfig::unredacted_for_tests();
assert_eq!(log.record_output(b"first", &config), 1);
assert_eq!(log.record_output(b"second", &config), 2);
assert_eq!(log.records.len(), 1);

Fields§

§limit: usize

Maximum records retained by Self::record; 0 retains none.

§next_sequence: u64

Sequence returned by the next record operation.

Allocation saturates at u64::MAX, after which that value repeats.

§records: Vec<TerminalEventRecord>

Sanitized records in insertion order, normally oldest to newest.

Implementations§

Source§

impl TerminalEventLog

Source

pub fn new(limit: usize) -> Self

Creates an empty log whose first sequence is one.

limit is exact and may be zero.

§Examples
use ailloli_ui_terminal_core::TerminalEventLog;

let log = TerminalEventLog::new(0);
assert_eq!(log.limit, 0);
assert_eq!(log.next_sequence, 1);
assert!(log.records.is_empty());
Source

pub fn record( &mut self, kind: TerminalEventKind, config: &TerminalSnapshotConfig, ) -> u64

Sanitizes and conditionally retains one event, returning its sequence.

The sequence counter uses saturating addition, so recordings at and after u64::MAX reuse that sequence. When over capacity, removing the oldest vector element shifts the remaining records and is linear in log length. See TerminalEventRecord for the scope of sanitization flags.

§Examples
use ailloli_ui_terminal_core::{
    TerminalEventKind, TerminalEventLog, TerminalSize, TerminalSnapshotConfig,
};

let mut log = TerminalEventLog::new(4);
let sequence = log.record(
    TerminalEventKind::Resize { size: TerminalSize::new(30, 100) },
    &TerminalSnapshotConfig::default(),
);
assert_eq!(sequence, 1);
assert_eq!(log.records.len(), 1);
Source

pub fn record_output( &mut self, bytes: &[u8], config: &TerminalSnapshotConfig, ) -> u64

Records sanitized terminal-output bytes and returns their sequence.

The stored payload may be truncated, lossily decoded, or redacted. The input slice is copied and is not retained by reference.

§Examples
use ailloli_ui_terminal_core::{TerminalEventKind, TerminalEventLog, TerminalSnapshotConfig};

let mut log = TerminalEventLog::new(1);
let sequence = log.record_output(b"token=abc", &TerminalSnapshotConfig::default());
assert_eq!(sequence, 1);
assert!(matches!(log.records[0].kind, TerminalEventKind::OutputBytes { .. }));
assert!(log.records[0].redacted);
Source

pub fn record_input( &mut self, bytes: &[u8], config: &TerminalSnapshotConfig, ) -> u64

Records sanitized terminal-input bytes and returns their sequence.

Input events are retained for inspection but skipped by Self::replay.

§Examples
use ailloli_ui_terminal_core::{TerminalEventLog, TerminalSnapshotConfig};

let mut log = TerminalEventLog::new(1);
log.record_input(b"yes\n", &TerminalSnapshotConfig::unredacted_for_tests());
let replay = log.replay(Default::default());
assert_eq!((replay.replayed_events, replay.skipped_events), (0, 1));
Source

pub fn snapshot( &self, config: &TerminalSnapshotConfig, ) -> Vec<TerminalEventRecord>

Copies the newest config.max_events records in stored order.

Existing records are not re-sanitized with config.redaction or config.max_event_bytes. A zero event limit returns an empty vector.

§Examples
use ailloli_ui_terminal_core::{TerminalEventLog, TerminalSnapshotConfig};

let recorded_with = TerminalSnapshotConfig::unredacted_for_tests();
let mut log = TerminalEventLog::new(4);
log.record_output(b"one", &recorded_with);
log.record_output(b"two", &recorded_with);
let copied = log.snapshot(&TerminalSnapshotConfig { max_events: 1, ..Default::default() });
assert_eq!(copied[0].sequence, 2);
Source

pub fn replay(&self, config: TerminalConfig) -> TerminalReplayResult

Replays supported stored events into a new terminal state.

Output is parsed, resize uses the state’s default resize policy, and warnings are appended. Input, diagnostic, and command events are skipped. Records are processed in vector order without validating sequence values. Because output was sanitized and may be truncated at record time, replay can intentionally differ from the original session.

Event counters use ordinary usize addition; theoretical overflow would panic with checks and wrap otherwise, though a vector that large cannot normally be represented.

§Examples
use ailloli_ui_terminal_core::{TerminalEventLog, TerminalSnapshotConfig};

let mut log = TerminalEventLog::new(2);
log.record_output(b"hello", &TerminalSnapshotConfig::unredacted_for_tests());
let replay = log.replay(Default::default());
assert_eq!((replay.replayed_events, replay.skipped_events), (1, 0));
assert!(replay.state.screen.lines[0].plain_text().contains("hello"));

Trait Implementations§

Source§

impl Clone for TerminalEventLog

Source§

fn clone(&self) -> TerminalEventLog

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 TerminalEventLog

Source§

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

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

impl Default for TerminalEventLog

Source§

fn default() -> Self

Creates an empty log retaining at most 2,000 records.

§Examples
use ailloli_ui_terminal_core::TerminalEventLog;
let log = TerminalEventLog::default();
assert_eq!(log.limit, 2_000);
Source§

impl<'de> Deserialize<'de> for TerminalEventLog

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 TerminalEventLog

Source§

fn eq(&self, other: &TerminalEventLog) -> 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 TerminalEventLog

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 TerminalEventLog

Source§

impl StructuralPartialEq for TerminalEventLog

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>,