1use std::fmt::{self, Display};
2
3pub struct CursorUp(pub u16);
4
5impl Display for CursorUp {
6 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7 write!(f, "\x1b[{}A", self.0)
8 }
9}
10
11pub struct CursorDown(pub u16);
12
13impl Display for CursorDown {
14 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15 write!(f, "\x1b[{}B", self.0)
16 }
17}
18
19pub struct CursorForward(pub u16);
20
21impl Display for CursorForward {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 write!(f, "\x1b[{}C", self.0)
24 }
25}
26
27pub struct CursorBackward(pub u16);
28
29impl Display for CursorBackward {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 write!(f, "\x1b[{}D", self.0)
32 }
33}
34
35pub struct CursorNextLine(pub u16);
36
37impl Display for CursorNextLine {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 write!(f, "\x1b[{}E", self.0)
40 }
41}
42
43pub struct CursorPrevLine(pub u16);
44
45impl Display for CursorPrevLine {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 write!(f, "\x1b[{}F", self.0)
48 }
49}
50
51pub struct CursorColumn(pub u16);
52
53impl Display for CursorColumn {
54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55 write!(f, "\x1b[{}G", self.0)
56 }
57}
58
59pub struct CursorPosition(pub u16, pub u16);
60
61impl Display for CursorPosition {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 write!(f, "\x1b[{};{}H", self.0, self.1)
64 }
65}
66
67pub const CURSOR_SAVE: &str = "\x1b[s";
68pub const CURSOR_RESTORE: &str = "\x1b[u";
69pub const CURSOR_HIDE: &str = "\x1b[?25l";
70pub const CURSOR_SHOW: &str = "\x1b[?25h";