diff --git a/src/ui.rs b/src/ui.rs index c4d74eb..229af7c 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -23,7 +23,6 @@ use std::{ use termion::{ input::TermRead, raw::{IntoRawMode, RawTerminal}, - screen::AlternateScreen, terminal_size, }; @@ -41,7 +40,7 @@ pub struct UI { pub size: (usize, usize), // cols, rows status: String, // status message, if any config: Config, // user config - out: RefCell>>, + out: RefCell>, } impl UI { @@ -54,13 +53,10 @@ impl UI { // Store raw terminal but don't enable it yet or switch the // screen. We don't want to stare at a fully blank screen // while waiting for a slow page to load. - let mut out = AlternateScreen::from( - stdout() - .into_raw_mode() - .expect("Failed to initialize raw mode."), - ); + let out = stdout() + .into_raw_mode() + .expect("Failed to initialize raw mode."); out.suspend_raw_mode(); - write!(out, "{}", termion::screen::ToMainScreen); UI { views: vec![], @@ -82,12 +78,20 @@ impl UI { write!(out, "{}", termion::screen::ToAlternateScreen); } + /// Clean up after ourselves. Should only be used after running in + /// interactive mode. + pub fn shutdown(&mut self) { + let mut out = self.out.borrow_mut(); + write!(out, "{}", termion::screen::ToMainScreen); + } + pub fn run(&mut self) -> Result<()> { self.startup(); while self.running { self.draw()?; self.update(); } + self.shutdown(); Ok(()) }