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
35
36
37
38
//! command to the terminal, such as moving the cursor and clearing the screen
use crossterm::{
    cursor,
    event::{
        DisableMouseCapture,
        EnableMouseCapture,
    },
    style,
    terminal,
    terminal::ClearType,
};
use std::io::Write;

pub(crate) fn reset_top(w: &mut dyn Write) -> crossterm::Result<()> {
    crossterm::queue!(
        w,
        style::ResetColor,
        terminal::Clear(ClearType::All),
        cursor::Hide,
        cursor::MoveTo(1, 1)
    )
}

pub(crate) fn init(w: &mut dyn Write) -> crossterm::Result<()> {
    crossterm::execute!(w, terminal::EnterAlternateScreen, EnableMouseCapture)?;
    terminal::enable_raw_mode()
}

pub(crate) fn finalize(w: &mut dyn Write) -> crossterm::Result<()> {
    crossterm::execute!(
        w,
        style::ResetColor,
        cursor::Show,
        terminal::LeaveAlternateScreen,
        DisableMouseCapture,
    )?;
    terminal::disable_raw_mode()
}