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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
pub fn col(n: usize) -> String {
    format!("\x1B[{}G", n)
}

pub fn up(n: usize) -> String {
    format!("\x1B[{}A", n)
}

pub fn left() -> &'static str {
    "\x1B[1D"
}

pub fn right() -> &'static str {
    "\x1B[1C"
}

pub fn clear_line() -> &'static str {
    "\x1B[2K"
}

pub fn clear_screen_down() -> &'static str {
    "\x1B[J"
}

pub fn save_position() -> &'static str {
    "\x1B7"
}

pub fn restore_position() -> &'static str {
    "\x1B8"
}

pub fn nowrap(test: &str) -> String {
    format!("\x1B[?7l{}\x1B[?7h", test)
}


#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_up() {
        assert_eq!("\x1B[2A", up(2));
    }

    #[test]
    fn test_left() {
        assert_eq!("\x1B[1D", left());
    }

    #[test]
    fn test_right() {
        assert_eq!("\x1B[1C", right());
    }

    #[test]
    fn test_clear_line() {
        assert_eq!("\x1B[2K", clear_line());
    }

    #[test]
    fn test_col() {
        assert_eq!("\x1B[8G", col(8));
    }

    #[test]
    fn test_clear_screen_down() {
        assert_eq!("\x1B[J", clear_screen_down());
    }

    #[test]
    fn test_save_position() {
        assert_eq!("\x1B7", save_position());
    }

    #[test]
    fn test_restore_position() {
        assert_eq!("\x1B8", restore_position());
    }

    #[test]
    fn test_nowrap() {
        assert_eq!("\x1B[?7lthing\x1B[?7h", nowrap("thing"));
    }
}