pub struct PtyOutputBatcher { /* private fields */ }Expand description
Single-threaded accumulator producing ordered PtyEvent::Output batches.
The batcher owns raw bytes and performs no decoding, parsing, redaction, or
I/O. It records wall-clock instants internally, so timeout tests/callers must
drive Self::tick using the real monotonic clock.
§Examples
use ailloli_ui_terminal_pty::{PtyEvent, PtyOutputBatcher};
let mut batcher = PtyOutputBatcher::new();
assert!(batcher.push(b"partial").is_empty());
assert_eq!(batcher.flush(), Some(PtyEvent::Output(b"partial".to_vec())));Implementations§
Source§impl PtyOutputBatcher
impl PtyOutputBatcher
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty batcher with PtyBatchConfig::default.
§Examples
use ailloli_ui_terminal_pty::PtyOutputBatcher;
let mut batcher = PtyOutputBatcher::new();
assert_eq!(batcher.flush(), None);Sourcepub fn with_config(config: PtyBatchConfig) -> Self
pub fn with_config(config: PtyBatchConfig) -> Self
Creates an empty batcher, clamping max_bytes to at least one.
The timeout is retained exactly, including zero. The normalized config is private; behavior rather than configuration introspection exposes it.
§Examples
use ailloli_ui_terminal_pty::{PtyBatchConfig, PtyEvent, PtyOutputBatcher};
let mut batcher = PtyOutputBatcher::with_config(PtyBatchConfig {
max_bytes: 0,
flush_timeout: std::time::Duration::ZERO,
});
assert_eq!(batcher.push(b"x"), vec![PtyEvent::Output(b"x".to_vec())]);Sourcepub fn push(&mut self, bytes: &[u8]) -> Vec<PtyEvent>
pub fn push(&mut self, bytes: &[u8]) -> Vec<PtyEvent>
Appends a raw chunk and returns zero or one flushed output event.
An empty slice is a complete no-op and does not reset the inactivity timer. A non-empty slice flushes the entire pending buffer when its final length reaches the byte trigger or the new slice contains any newline. Bytes after that newline remain in the same event; input is never split. Otherwise the timer is reset to now and an empty vector is returned.
§Panics
Growing the pending buffer can panic or abort if allocation fails.
§Examples
use ailloli_ui_terminal_pty::{PtyEvent, PtyOutputBatcher};
let mut batcher = PtyOutputBatcher::new();
assert!(batcher.push(b"a").is_empty());
assert_eq!(batcher.push(b"b\nc"), vec![PtyEvent::Output(b"ab\nc".to_vec())]);Sourcepub fn tick(&mut self) -> Option<PtyEvent>
pub fn tick(&mut self) -> Option<PtyEvent>
Flushes pending bytes once the configured inactivity timeout has elapsed.
Returns None when empty or still inside the timeout. A successful flush
resets the internal timer.
§Examples
use std::time::Duration;
use ailloli_ui_terminal_pty::{PtyBatchConfig, PtyEvent, PtyOutputBatcher};
let mut batcher = PtyOutputBatcher::with_config(PtyBatchConfig {
max_bytes: 10,
flush_timeout: Duration::ZERO,
});
assert!(batcher.push(b"x").is_empty());
assert_eq!(batcher.tick(), Some(PtyEvent::Output(b"x".to_vec())));Sourcepub fn flush(&mut self) -> Option<PtyEvent>
pub fn flush(&mut self) -> Option<PtyEvent>
Immediately moves all pending bytes into one output event.
Returns None when empty. The replacement pending vector has no promised
retained capacity, and the inactivity timestamp is cleared.
§Examples
use ailloli_ui_terminal_pty::{PtyEvent, PtyOutputBatcher};
let mut batcher = PtyOutputBatcher::new(); batcher.push(b"raw");
assert_eq!(batcher.flush(), Some(PtyEvent::Output(b"raw".to_vec())));
assert_eq!(batcher.flush(), None);Trait Implementations§
Source§impl Debug for PtyOutputBatcher
impl Debug for PtyOutputBatcher
Auto Trait Implementations§
impl Freeze for PtyOutputBatcher
impl RefUnwindSafe for PtyOutputBatcher
impl Send for PtyOutputBatcher
impl Sync for PtyOutputBatcher
impl Unpin for PtyOutputBatcher
impl UnwindSafe for PtyOutputBatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.