indicatif/
term_like.rs
1use std::fmt::Debug;
2use std::io;
3
4use console::Term;
5
6pub trait TermLike: Debug + Send + Sync {
12 fn width(&self) -> u16;
14 fn height(&self) -> u16 {
16 20 }
19
20 fn move_cursor_up(&self, n: usize) -> io::Result<()>;
22 fn move_cursor_down(&self, n: usize) -> io::Result<()>;
24 fn move_cursor_right(&self, n: usize) -> io::Result<()>;
26 fn move_cursor_left(&self, n: usize) -> io::Result<()>;
28
29 fn write_line(&self, s: &str) -> io::Result<()>;
31 fn write_str(&self, s: &str) -> io::Result<()>;
33 fn clear_line(&self) -> io::Result<()>;
35
36 fn flush(&self) -> io::Result<()>;
37}
38
39impl TermLike for Term {
40 fn width(&self) -> u16 {
41 self.size().1
42 }
43
44 fn height(&self) -> u16 {
45 self.size().0
46 }
47
48 fn move_cursor_up(&self, n: usize) -> io::Result<()> {
49 self.move_cursor_up(n)
50 }
51
52 fn move_cursor_down(&self, n: usize) -> io::Result<()> {
53 self.move_cursor_down(n)
54 }
55
56 fn move_cursor_right(&self, n: usize) -> io::Result<()> {
57 self.move_cursor_right(n)
58 }
59
60 fn move_cursor_left(&self, n: usize) -> io::Result<()> {
61 self.move_cursor_left(n)
62 }
63
64 fn write_line(&self, s: &str) -> io::Result<()> {
65 self.write_line(s)
66 }
67
68 fn write_str(&self, s: &str) -> io::Result<()> {
69 self.write_str(s)
70 }
71
72 fn clear_line(&self) -> io::Result<()> {
73 self.clear_line()
74 }
75
76 fn flush(&self) -> io::Result<()> {
77 self.flush()
78 }
79}