minicrossterm/examples/alternate_screen.rs
Timon 1e332daaed
Refactor and API stabilization (#115)
- Major refactor and cleanup.
- Improved performance; 
    - No locking when writing to stdout. 
    - UNIX doesn't have any dynamic dispatch anymore. 
    - Windows has improved the way to check if ANSI modes are enabled.
    - Removed lot's of complex API calls: `from_screen`, `from_output`
    - Removed `Arc<TerminalOutput>` from all internal Api's. 
- Removed termios dependency for UNIX systems.
- Upgraded deps.
- Removed about 1000 lines of code
    - `TerminalOutput` 
    - `Screen`
    - unsafe code
    - Some duplicated code introduced by a previous refactor.
- Raw modes UNIX systems improved     
- Added `NoItalic` attribute
2019-04-10 23:46:30 +02:00

45 lines
1.2 KiB
Rust

extern crate crossterm;
use crossterm::{style, AlternateScreen, ClearType, Color, Crossterm};
use std::{thread, time};
fn print_wait_screen() {
let crossterm = Crossterm::new();
let terminal = crossterm.terminal();
let cursor = crossterm.cursor();
terminal.clear(ClearType::All);
cursor.goto(0, 0);
cursor.hide();
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.
for i in 1..5 {
// print the current counter at the line of `Seconds to Go: {counter}`
cursor.goto(10, 2);
println!(
"{}",
style(format!("{} of the 5 items processed", i))
.with(Color::Red)
.on(Color::Blue)
);
// 1 second delay
thread::sleep(time::Duration::from_secs(1));
}
}
/// print wait screen on alternate screen, then switch back.
pub fn print_wait_screen_on_alternate_window() {
if let Ok(alternate) = AlternateScreen::to_alternate(false) {
print_wait_screen();
}
}
fn main() {
print_wait_screen_on_alternate_window();
}