Macro crossterm::queue

source ·
macro_rules! queue {
    ($writer:expr $(, $command:expr)* $(,)?) => { ... };
}
Expand description

Queues one or more command(s) for further execution.

Queued commands must be flushed to the underlying device to be executed. This generally happens in the following cases:

  • When flush is called manually on the given type implementing io::Write.
  • The terminal will flush automatically if the buffer is full.
  • Each line is flushed in case of stdout, because it is line buffered.

Arguments

  • std::io::Writer

    ANSI escape codes are written on the given ‘writer’, after which they are flushed.

  • Command

    One or more commands

Examples

use std::io::{Write, stdout};
use crossterm::{queue, style::Print};

let mut stdout = stdout();

// `Print` will executed executed when `flush` is called.
queue!(stdout, Print("foo".to_string()));

// some other code (no execution happening here) ...

// when calling `flush` on `stdout`, all commands will be written to the stdout and therefore executed.
stdout.flush();

// ==== Output ====
// foo

Have a look over at the Command API for more details.

Notes

In case of Windows versions lower than 10, a direct WinAPI call will be made. The reason for this is that Windows versions lower than 10 do not support ANSI codes, and can therefore not be written to the given writer. Therefore, there is no difference between execute and queue for those old Windows versions.