2
0
mirror of https://github.com/xvxx/phetch synced 2024-11-10 13:10:54 +00:00

handle switching screens on our own

print mode doesn't want alternate mode,
so we won't use it in that case
This commit is contained in:
chris west 2020-01-11 15:23:17 -08:00
parent d587df8def
commit 7cf9e25c6b

View File

@ -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<AlternateScreen<RawTerminal<Stdout>>>,
out: RefCell<RawTerminal<Stdout>>,
}
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(())
}