DEVELOPMENT ENVIRONMENT

~liljamo/entamin

ref: f2422416092709b8754eeb9d5872eed31b0e3277 entamin/src/terminal.rs -rw-r--r-- 949 bytes
f2422416Jonni Liljamo feat: include year in metadata title 9 hours ago
                                                                                
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
30
31
32
33
34
/*
 * Copyright (C) 2024 Jonni Liljamo <jonni@liljamo.com>
 *
 * This file is licensed under GPL-3.0-or-later, see NOTICE and LICENSE for
 * more information.
 */

use std::io::Stdout;

use crossterm::{cursor, terminal, ExecutableCommand};

pub fn clear_and_reset_cursor(stdout: &mut Stdout) {
    stdout
        .execute(terminal::Clear(terminal::ClearType::All))
        .expect("could not clear terminal");
    stdout
        .execute(cursor::MoveTo(0, 0))
        .expect("could not move cursor to 0,0");
}

pub fn save_cursor(stdout: &mut Stdout) {
    stdout
        .execute(cursor::SavePosition)
        .expect("could not save cursor position");
}

pub fn restore_cursor_and_clear(stdout: &mut Stdout) {
    stdout
        .execute(cursor::RestorePosition)
        .expect("could not restore cursor position");
    stdout
        .execute(terminal::Clear(terminal::ClearType::FromCursorDown))
        .expect("could not clear terminal");
}