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: usizeMaximum records retained by Self::record; 0 retains none.
next_sequence: u64Sequence 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
impl TerminalEventLog
Sourcepub fn new(limit: usize) -> Self
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());Sourcepub fn record(
&mut self,
kind: TerminalEventKind,
config: &TerminalSnapshotConfig,
) -> u64
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);Sourcepub fn record_output(
&mut self,
bytes: &[u8],
config: &TerminalSnapshotConfig,
) -> u64
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);Sourcepub fn record_input(
&mut self,
bytes: &[u8],
config: &TerminalSnapshotConfig,
) -> u64
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));Sourcepub fn snapshot(
&self,
config: &TerminalSnapshotConfig,
) -> Vec<TerminalEventRecord>
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);Sourcepub fn replay(&self, config: TerminalConfig) -> TerminalReplayResult
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
impl Clone for TerminalEventLog
Source§fn clone(&self) -> TerminalEventLog
fn clone(&self) -> TerminalEventLog
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more