-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.rs
More file actions
28 lines (23 loc) · 876 Bytes
/
util.rs
File metadata and controls
28 lines (23 loc) · 876 Bytes
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
use crossterm::{
event::{DisableMouseCapture, EnableMouseCapture},
execute,
terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode},
};
use miette::IntoDiagnostic;
use ratatui::prelude::*;
use std::io;
pub fn setup_terminal() -> miette::Result<Terminal<CrosstermBackend<io::Stdout>>> {
enable_raw_mode().into_diagnostic()?;
let mut stdout = io::stdout();
execute!(stdout, EnterAlternateScreen, EnableMouseCapture).into_diagnostic()?;
let backend = CrosstermBackend::new(stdout);
let terminal = Terminal::new(backend).into_diagnostic()?;
Ok(terminal)
}
pub fn restore_terminal() -> miette::Result<()> {
// Restore terminal
disable_raw_mode().into_diagnostic()?;
let mut stdout = io::stdout();
execute!(stdout, LeaveAlternateScreen, DisableMouseCapture).into_diagnostic()?;
Ok(())
}