diff --git a/examples/crossterm_demo.rs b/examples/crossterm_demo.rs index 581ccf43..d82e709d 100644 --- a/examples/crossterm_demo.rs +++ b/examples/crossterm_demo.rs @@ -10,6 +10,7 @@ use std::time::Duration; use structopt::StructOpt; use tui::backend::CrosstermBackend; use tui::Terminal; +use crossterm; use crate::demo::{ui, App}; @@ -30,7 +31,9 @@ fn main() -> Result<(), failure::Error> { let cli = Cli::from_args(); stderrlog::new().quiet(!cli.log).verbosity(4).init()?; - let backend = CrosstermBackend::new(); + let screen = crossterm::Screen::default(); + let alternate_screen = screen.enable_alternate_modes(true)?; + let backend = CrosstermBackend::with_alternate_screen(alternate_screen)?; let mut terminal = Terminal::new(backend)?; terminal.hide_cursor()?; diff --git a/src/backend/crossterm.rs b/src/backend/crossterm.rs index 2f490a65..8e0ecec7 100644 --- a/src/backend/crossterm.rs +++ b/src/backend/crossterm.rs @@ -7,7 +7,7 @@ use crate::style::{Color, Modifier}; use crossterm::error::ErrorKind; pub struct CrosstermBackend { - screen: crossterm::Screen, + screen: Option, crossterm: crossterm::Crossterm, // Need to keep the AlternateScreen around even when not using it directly, // see https://github.com/TimonPost/crossterm/issues/88 @@ -19,7 +19,7 @@ impl Default for CrosstermBackend { let screen = crossterm::Screen::default(); let crossterm = crossterm::Crossterm::from_screen(&screen); CrosstermBackend { - screen, + screen: Some(screen), crossterm, alternate_screen: None, } @@ -34,24 +34,26 @@ impl CrosstermBackend { pub fn with_screen(screen: crossterm::Screen) -> CrosstermBackend { let crossterm = crossterm::Crossterm::from_screen(&screen); CrosstermBackend { - screen, + screen: Some(screen), crossterm, alternate_screen: None, } } - pub fn with_alternate_screen(screen: crossterm::Screen, raw_mode: bool) -> Result { - let alternate_screen = screen.enable_alternate_modes(raw_mode)?; + pub fn with_alternate_screen(alternate_screen: crossterm::AlternateScreen) -> Result { let crossterm = crossterm::Crossterm::from_screen(&alternate_screen.screen); Ok(CrosstermBackend { - screen, + screen: None, crossterm, alternate_screen: Some(alternate_screen), }) } - pub fn screen(&self) -> &crossterm::Screen { - &self.screen + pub fn screen(&self) -> Option<&crossterm::Screen> { + match &self.screen { + Some(screen) => Some(&screen), + None => None, + } } pub fn alternate_screen(&self) -> Option<&crossterm::AlternateScreen> {