Debian Codegraph @

debian/rust-vendor/console/src/common_term.rs

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