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:
parent
d587df8def
commit
7cf9e25c6b
20
src/ui.rs
20
src/ui.rs
@ -23,7 +23,6 @@ use std::{
|
|||||||
use termion::{
|
use termion::{
|
||||||
input::TermRead,
|
input::TermRead,
|
||||||
raw::{IntoRawMode, RawTerminal},
|
raw::{IntoRawMode, RawTerminal},
|
||||||
screen::AlternateScreen,
|
|
||||||
terminal_size,
|
terminal_size,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ pub struct UI {
|
|||||||
pub size: (usize, usize), // cols, rows
|
pub size: (usize, usize), // cols, rows
|
||||||
status: String, // status message, if any
|
status: String, // status message, if any
|
||||||
config: Config, // user config
|
config: Config, // user config
|
||||||
out: RefCell<AlternateScreen<RawTerminal<Stdout>>>,
|
out: RefCell<RawTerminal<Stdout>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UI {
|
impl UI {
|
||||||
@ -54,13 +53,10 @@ impl UI {
|
|||||||
// Store raw terminal but don't enable it yet or switch the
|
// Store raw terminal but don't enable it yet or switch the
|
||||||
// screen. We don't want to stare at a fully blank screen
|
// screen. We don't want to stare at a fully blank screen
|
||||||
// while waiting for a slow page to load.
|
// while waiting for a slow page to load.
|
||||||
let mut out = AlternateScreen::from(
|
let out = stdout()
|
||||||
stdout()
|
.into_raw_mode()
|
||||||
.into_raw_mode()
|
.expect("Failed to initialize raw mode.");
|
||||||
.expect("Failed to initialize raw mode."),
|
|
||||||
);
|
|
||||||
out.suspend_raw_mode();
|
out.suspend_raw_mode();
|
||||||
write!(out, "{}", termion::screen::ToMainScreen);
|
|
||||||
|
|
||||||
UI {
|
UI {
|
||||||
views: vec![],
|
views: vec![],
|
||||||
@ -82,12 +78,20 @@ impl UI {
|
|||||||
write!(out, "{}", termion::screen::ToAlternateScreen);
|
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<()> {
|
pub fn run(&mut self) -> Result<()> {
|
||||||
self.startup();
|
self.startup();
|
||||||
while self.running {
|
while self.running {
|
||||||
self.draw()?;
|
self.draw()?;
|
||||||
self.update();
|
self.update();
|
||||||
}
|
}
|
||||||
|
self.shutdown();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user