diff options
Diffstat (limited to 'src/tui.rs')
-rw-r--r-- | src/tui.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/tui.rs b/src/tui.rs new file mode 100644 index 0000000..7bae1ab --- /dev/null +++ b/src/tui.rs @@ -0,0 +1,24 @@ +use crossterm::{execute, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}}; + +use ratatui::{ + prelude::CrosstermBackend, + Terminal, +}; + +use std::io::{self, stdout, Stdout}; + + +pub type Tui = Terminal<CrosstermBackend<Stdout>>; + +pub fn init() -> io::Result<Tui> { + execute!(stdout(), EnterAlternateScreen)?; + enable_raw_mode()?; + Terminal::new(CrosstermBackend::new(stdout())) +} + +pub fn restore() -> io::Result<()> { + execute!(stdout(), LeaveAlternateScreen)?; + disable_raw_mode()?; + + Ok(()) +} |