1 | use std::io; |
2 | |
3 | use crate::term::Term; |
4 | |
5 | pub fn move_cursor_down(out: &Term, n: usize) -> io::Result<()> { |
6 | if n > 0 { |
7 | out.write_str(&format!(" \x1b[ {}B" , n)) |
8 | } else { |
9 | Ok(()) |
10 | } |
11 | } |
12 | |
13 | pub fn move_cursor_up(out: &Term, n: usize) -> io::Result<()> { |
14 | if n > 0 { |
15 | out.write_str(&format!(" \x1b[ {}A" , n)) |
16 | } else { |
17 | Ok(()) |
18 | } |
19 | } |
20 | pub fn move_cursor_left(out: &Term, n: usize) -> io::Result<()> { |
21 | if n > 0 { |
22 | out.write_str(&format!(" \x1b[ {}D" , n)) |
23 | } else { |
24 | Ok(()) |
25 | } |
26 | } |
27 | |
28 | pub fn move_cursor_right(out: &Term, n: usize) -> io::Result<()> { |
29 | if n > 0 { |
30 | out.write_str(&format!(" \x1b[ {}C" , n)) |
31 | } else { |
32 | Ok(()) |
33 | } |
34 | } |
35 | |
36 | #[inline ] |
37 | pub fn move_cursor_to(out: &Term, x: usize, y: usize) -> io::Result<()> { |
38 | out.write_str(&format!(" \x1B[ {}; {}H" , y + 1, x + 1)) |
39 | } |
40 | |
41 | pub fn clear_chars(out: &Term, n: usize) -> io::Result<()> { |
42 | if n > 0 { |
43 | out.write_str(&format!(" \x1b[ {}D \x1b[0K" , n)) |
44 | } else { |
45 | Ok(()) |
46 | } |
47 | } |
48 | |
49 | #[inline ] |
50 | pub fn clear_line(out: &Term) -> io::Result<()> { |
51 | out.write_str(" \r\x1b[2K" ) |
52 | } |
53 | |
54 | #[inline ] |
55 | pub fn clear_screen(out: &Term) -> io::Result<()> { |
56 | out.write_str(" \r\x1b[2J \r\x1b[H" ) |
57 | } |
58 | |
59 | #[inline ] |
60 | pub fn clear_to_end_of_screen(out: &Term) -> io::Result<()> { |
61 | out.write_str(" \r\x1b[0J" ) |
62 | } |
63 | |
64 | #[inline ] |
65 | pub fn show_cursor(out: &Term) -> io::Result<()> { |
66 | out.write_str(" \x1b[?25h" ) |
67 | } |
68 | |
69 | #[inline ] |
70 | pub fn hide_cursor(out: &Term) -> io::Result<()> { |
71 | out.write_str(" \x1b[?25l" ) |
72 | } |
73 | |