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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//!
//! Clear line helper (ANSI escape codes to clear the terminal line)
//!

use std::fmt;

pub struct ClearLine;

impl fmt::Display for ClearLine {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "\x1B[2K\r")
    }
}

impl AsRef<[u8]> for ClearLine {
    fn as_ref(&self) -> &'static [u8] {
        "\x1B[2K\r".as_bytes()
    }
}

impl AsRef<str> for ClearLine {
    fn as_ref(&self) -> &'static str {
        "\x1B[2K\r"
    }
}

pub struct ClearScreen;

impl fmt::Display for ClearScreen {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "\x1B[2J")
    }
}

impl AsRef<[u8]> for ClearScreen {
    fn as_ref(&self) -> &'static [u8] {
        "\x1B[2J".as_bytes()
    }
}

impl AsRef<str> for ClearScreen {
    fn as_ref(&self) -> &'static str {
        "\x1B[2J"
    }
}