pub struct TerminalParser { /* private fields */ }Expand description
Stateful, incremental VT100 SGR parser.
Each task output stream (stdout / stderr) should have its own TerminalParser
instance because SGR state is per-stream.
§Usage
ⓘ
let mut parser = TerminalParser::new();
for chunk in byte_stream {
for line in parser.push(&chunk) {
// handle completed line
}
}
if let Some(line) = parser.flush() {
// handle trailing line with no newline
}Implementations§
Source§impl TerminalParser
impl TerminalParser
pub fn new() -> Self
Sourcepub fn push(&mut self, bytes: &[u8]) -> Vec<StyledLine>
pub fn push(&mut self, bytes: &[u8]) -> Vec<StyledLine>
Push a raw byte chunk through the parser.
Returns all lines that were completed (terminated by \n) within
this chunk. Partial lines are buffered internally.
Sourcepub fn flush(&mut self) -> Option<StyledLine>
pub fn flush(&mut self) -> Option<StyledLine>
Flush any remaining partial line (content that has no trailing \n).
Should be called once when the underlying stream is closed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TerminalParser
impl RefUnwindSafe for TerminalParser
impl Send for TerminalParser
impl Sync for TerminalParser
impl Unpin for TerminalParser
impl UnsafeUnpin for TerminalParser
impl UnwindSafe for TerminalParser
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
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn 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.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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.Source§fn as_any(&self) -> &(dyn Any + 'static)
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.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more