Skip to main content

CommandQueue

Struct CommandQueue 

Source
pub struct CommandQueue<W> { /* private fields */ }
Available on crate feature 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>

Source

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.

Source

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>

Source

pub fn new(writer: W) -> CommandQueue<W>

Creates an empty command queue for writer.

Source

pub fn with_capacity(capacity: usize, writer: W) -> CommandQueue<W>

Creates an empty command queue with space for at least capacity bytes.

Source

pub fn buffered_len(&self) -> usize

Returns the number of command bytes that have not been written.

Source

pub fn is_empty(&self) -> bool

Returns true when no command bytes are waiting to be written.

Source§

impl CommandQueue<Stdout>

Source

pub fn stdout() -> CommandQueue<Stdout>

Creates an empty command queue that writes to standard output.

Source§

impl CommandQueue<Stderr>

Source

pub fn stderr() -> CommandQueue<Stderr>

Creates an empty command queue that writes to standard error.

Source§

impl<W> CommandQueue<W>
where W: AsyncWrite,

Source

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§

Source§

impl<W> Debug for CommandQueue<W>
where W: Debug,

Source§

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

Formats the value using the given formatter. Read more

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Message for T
where T: Send + 'static,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
§

impl<T> Ungil for T
where T: Send,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more