minicrossterm/examples/terminal/alternate_screen.rs

47 lines
1.3 KiB
Rust
Raw Normal View History

extern crate crossterm;
use crossterm::style::{style, Color};
use crossterm::terminal::{self, ClearType};
use crossterm::{Crossterm, Screen};
2018-07-02 06:43:43 +10:00
use std::io::{stdout, Write};
use std::{thread, time};
fn print_wait_screen(screen: &Screen) {
let crossterm = Crossterm::from_screen(screen);
let terminal = crossterm.terminal();
let cursor = crossterm.cursor();
2018-08-03 20:01:04 +10:00
terminal.clear(ClearType::All);
2018-07-02 06:43:43 +10:00
cursor.goto(0, 0);
cursor.hide();
2018-07-02 06:43:43 +10:00
terminal.write(
"Welcome to the wait screen.\n\
Please wait a few seconds until we arrive back at the main screen.\n\
Progress: ",
);
// print some progress example.
2018-07-02 06:43:43 +10:00
for i in 1..5 {
// print the current counter at the line of `Seconds to Go: {counter}`
cursor.goto(10, 2);
style(format!("{} of the 5 items processed", i))
.with(Color::Red)
.on(Color::Blue)
.paint(&screen);
// 1 second delay
thread::sleep(time::Duration::from_secs(1));
}
}
/// print wait screen on alternate screen, then switch back.
2018-08-03 20:01:04 +10:00
pub fn print_wait_screen_on_alternate_window() {
let screen = Screen::default();
if let Ok(alternate) = screen.enable_alternate_modes(false) {
print_wait_screen(&alternate.screen);
}
2018-07-02 06:43:43 +10:00
}