pub struct CommandQueue<W> { /* private fields */ }term only.Expand description
A buffered queue of terminal commands for a Compio asynchronous writer.
Commands are encoded with
Command::write_ansi and written in one
ordered batch when flush is awaited. The writer can be
Compio’s standard output handle or any other type that implements
compio_io::AsyncWrite.
Call flush before this value is dropped. Dropping it
discards commands that are still queued.
§Example
use std::io;
use compio_term::{Queueable, cursor::MoveTo, style::Print};
#[compio_macros::main]
async fn main() -> io::Result<()> {
let mut stdout = compio_fs::stdout();
let mut output = stdout.queue(MoveTo(0, 0))?;
output.queue_many((Print("ready"), Print("\r\n")))?;
output.flush().await
}Implementations§
Source§impl<W> CommandQueue<W>
impl<W> CommandQueue<W>
Sourcepub fn queue(
&mut self,
command: impl Command,
) -> Result<&mut CommandQueue<W>, Error>
pub fn queue( &mut self, command: impl Command, ) -> Result<&mut CommandQueue<W>, Error>
Adds a command without writing to the underlying writer.
If the command cannot render its ANSI representation, this method removes any bytes that the failed command added. Commands that were already queued remain intact.
Sourcepub fn queue_many(
&mut self,
commands: impl Commands,
) -> Result<&mut CommandQueue<W>, Error>
pub fn queue_many( &mut self, commands: impl Commands, ) -> Result<&mut CommandQueue<W>, Error>
Adds an ordered batch of commands without writing to the underlying writer.
If any command cannot render its ANSI representation, this method removes every byte added by this call. Commands that were already queued remain intact.
Source§impl<W> CommandQueue<W>
impl<W> CommandQueue<W>
Sourcepub fn new(writer: W) -> CommandQueue<W>
pub fn new(writer: W) -> CommandQueue<W>
Creates an empty command queue for writer.
Sourcepub fn with_capacity(capacity: usize, writer: W) -> CommandQueue<W>
pub fn with_capacity(capacity: usize, writer: W) -> CommandQueue<W>
Creates an empty command queue with space for at least capacity bytes.
Sourcepub fn buffered_len(&self) -> usize
pub fn buffered_len(&self) -> usize
Returns the number of command bytes that have not been written.
Source§impl CommandQueue<Stdout>
impl CommandQueue<Stdout>
Sourcepub fn stdout() -> CommandQueue<Stdout>
pub fn stdout() -> CommandQueue<Stdout>
Creates an empty command queue that writes to standard output.
Source§impl CommandQueue<Stderr>
impl CommandQueue<Stderr>
Sourcepub fn stderr() -> CommandQueue<Stderr>
pub fn stderr() -> CommandQueue<Stderr>
Creates an empty command queue that writes to standard error.
Source§impl<W> CommandQueue<W>where
W: AsyncWrite,
impl<W> CommandQueue<W>where
W: AsyncWrite,
Sourcepub async fn flush(&mut self) -> Result<(), Error>
pub async fn flush(&mut self) -> Result<(), Error>
Writes all queued commands and flushes the underlying writer.
A partial write is resumed at the first unwritten byte if this method is called again after a write error. Commands queued after that error stay after the remaining bytes from the failed batch.
Trait Implementations§
Auto Trait Implementations§
impl<W> Freeze for CommandQueue<W>where
W: Freeze,
impl<W> RefUnwindSafe for CommandQueue<W>where
W: RefUnwindSafe,
impl<W> Send for CommandQueue<W>where
W: Send,
impl<W> Sync for CommandQueue<W>where
W: Sync,
impl<W> Unpin for CommandQueue<W>where
W: Unpin,
impl<W> UnsafeUnpin for CommandQueue<W>where
W: UnsafeUnpin,
impl<W> UnwindSafe for CommandQueue<W>where
W: UnwindSafe,
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
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> ⓘ
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> ⓘ
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