aboutsummaryrefslogtreecommitdiffstats
path: root/src/cursor.rs
blob: 7913d3cb7535a9962320182eaa867e4d47fe3151 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#[derive(Debug, Clone, Copy)]
pub enum Direction {
    Up,
    Down,
    Left,
    Right,
}

pub fn move_cursor(direction: Direction, n: usize) {
    if n == 0 {
        return;
    }

    let code = match direction {
        Direction::Up => 'A',
        Direction::Down => 'B',
        Direction::Right => 'C',
        Direction::Left => 'D',
    };

    print!("\x1b[{n}{code}");
}

/// Represents a cursor position
#[derive(Debug, Clone, Copy)]
pub struct CursorPos {
    pub row: usize,
    pub col: usize,
}