Struct PtyOutputBatcher

Source
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

Source

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

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

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

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

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

Source§

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

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

impl Default for PtyOutputBatcher

Source§

fn default() -> Self

Creates the same empty batcher as Self::new.

§Examples
use ailloli_ui_terminal_pty::PtyOutputBatcher;
assert_eq!(PtyOutputBatcher::default().flush(), None);

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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, 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.