1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// Append a the first few characters of an ANSI escape code to the given string.
#[macro_export]
macro_rules! csi {
    ($( $l:expr ),*) => { concat!("\x1B[", $( $l ),*) };
}

/// Write a string to standard output whereafter the screen will be flushed.
#[macro_export]
macro_rules! write_cout {
    ($string:expr) => {{
        let stdout = ::std::io::stdout();
        let mut stdout = stdout.lock();
        let mut size = 0;

        let result = stdout.write($string.as_bytes());

        size += match result {
            Ok(size) => size,
            Err(e) => return Err(crossterm_utils::ErrorKind::IoError(e)),
        };

        match stdout.flush() {
            Ok(_) => Ok(size),
            Err(e) => Err(crossterm_utils::ErrorKind::IoError(e)),
        }
    }};
}