[][src]Macro crossterm::queue

macro_rules! queue {
    ($write:expr, $($command:expr), *) => { ... };
}

Queue one or more command(s) for execution in the near future.

Queued commands will be executed in the following cases:

  • When you manually call flush on the given writer.
  • When the buffer is to full, then the terminal will flush for you.
  • Incase of stdout each line, because stdout is line buffered.

Parameters

  • std::io::Writer

    Crossterm will write the ANSI escape codes to this given writer (No flush will be done).

  • Command

    Give one or more commands that you want to queue for execution

Example


use std::io::{Write, stdout};

use crossterm::{queue, Output};

let mut stdout = stdout();

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

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

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

Remarks

  • In the case of UNIX and windows 10, ANSI codes are written to the given 'writer'.
  • In case of Windows versions lower than 10, a direct WinApi call will be made. This is happening because windows versions lower then 10 do not support ANSI codes, and thus they can't be written to the given buffer. Because of that there is no difference between execute and queue for those windows versions.
  • Queuing might sound that there is some scheduling going on, however, this means that we write to the stdout without flushing which will cause commands to be stored in the buffer without them being written to the terminal.