1use std::io;
2
3use crate::term::Term;
4
5pub 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
13pub 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}
20pub 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
28pub 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]
37pub 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
41pub 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]
50pub fn clear_line(out: &Term) -> io::Result<()> {
51 out.write_str("\r\x1b[2K")
52}
53
54#[inline]
55pub fn clear_screen(out: &Term) -> io::Result<()> {
56 out.write_str("\r\x1b[2J\r\x1b[H")
57}
58
59#[inline]
60pub fn clear_to_end_of_screen(out: &Term) -> io::Result<()> {
61 out.write_str("\r\x1b[0J")
62}
63
64#[inline]
65pub fn show_cursor(out: &Term) -> io::Result<()> {
66 out.write_str("\x1b[?25h")
67}
68
69#[inline]
70pub fn hide_cursor(out: &Term) -> io::Result<()> {
71 out.write_str("\x1b[?25l")
72}
73