src/readline/cursor.rs 674 B raw
1
//! ANSI escape sequences for cursor movement.
2
3
/// Utilities for cursor movement in the terminal.
4
pub struct Cursor;
5
6
impl Cursor {
7
    /// Generates an ANSI escape sequence to move the cursor `n` positions to the left.
8
    /// Returns an empty string if n is 0.
9
    pub fn left(n: usize) -> String {
10
        if n == 0 {
11
            return String::new();
12
        }
13
        format!("\x1b[{n}D")
14
    }
15
16
    /// Generates an ANSI escape sequence to move the cursor `n` positions to the right.
17
    /// Returns an empty string if n is 0.
18
    pub fn right(n: usize) -> String {
19
        if n == 0 {
20
            return String::new();
21
        }
22
        format!("\x1b[{n}C")
23
    }
24
}