Nothing to see here, move along
1use core::fmt;
2
3pub struct CursorTo {
4 pub row: u16,
5 pub col: u16,
6}
7
8impl fmt::Display for CursorTo {
9 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10 write!(f, "\x1b[{};{}H", self.row, self.col)
11 }
12}
13
14pub struct CursorUp(pub u16);
15pub struct CursorDown(pub u16);
16pub struct CursorForward(pub u16);
17pub struct CursorBack(pub u16);
18
19impl fmt::Display for CursorUp {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 write!(f, "\x1b[{}A", self.0)
22 }
23}
24
25impl fmt::Display for CursorDown {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 write!(f, "\x1b[{}B", self.0)
28 }
29}
30
31impl fmt::Display for CursorForward {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 write!(f, "\x1b[{}C", self.0)
34 }
35}
36
37impl fmt::Display for CursorBack {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 write!(f, "\x1b[{}D", self.0)
40 }
41}
42
43pub struct CursorSave;
44pub struct CursorRestore;
45
46impl fmt::Display for CursorSave {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 f.write_str("\x1b[s")
49 }
50}
51
52impl fmt::Display for CursorRestore {
53 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 f.write_str("\x1b[u")
55 }
56}
57
58pub struct CursorHide;
59pub struct CursorShow;
60
61impl fmt::Display for CursorHide {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 f.write_str("\x1b[?25l")
64 }
65}
66
67impl fmt::Display for CursorShow {
68 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69 f.write_str("\x1b[?25h")
70 }
71}
72
73pub struct ClearScreen;
74pub struct ClearScreenFull;
75pub struct ClearToEnd;
76pub struct ClearLine;
77pub struct ClearLineToEnd;
78
79impl fmt::Display for ClearScreen {
80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81 f.write_str("\x1b[J")
82 }
83}
84
85impl fmt::Display for ClearScreenFull {
86 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
87 f.write_str("\x1b[2J")
88 }
89}
90
91impl fmt::Display for ClearToEnd {
92 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93 f.write_str("\x1b[J")
94 }
95}
96
97impl fmt::Display for ClearLine {
98 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
99 f.write_str("\x1b[2K")
100 }
101}
102
103impl fmt::Display for ClearLineToEnd {
104 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
105 f.write_str("\x1b[K")
106 }
107}
108
109pub struct ScrollRegion {
110 pub top: u16,
111 pub bottom: u16,
112}
113
114impl fmt::Display for ScrollRegion {
115 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
116 write!(f, "\x1b[{};{}r", self.top, self.bottom)
117 }
118}
119
120pub struct ScrollRegionReset;
121
122impl fmt::Display for ScrollRegionReset {
123 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
124 f.write_str("\x1b[r")
125 }
126}
127
128pub struct ScrollUp(pub u16);
129pub struct ScrollDown(pub u16);
130
131impl fmt::Display for ScrollUp {
132 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133 write!(f, "\x1b[{}S", self.0)
134 }
135}
136
137impl fmt::Display for ScrollDown {
138 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139 write!(f, "\x1b[{}T", self.0)
140 }
141}
142
143pub struct CursorColumn(pub u16);
144
145impl fmt::Display for CursorColumn {
146 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
147 write!(f, "\x1b[{}G", self.0)
148 }
149}