2018-06-14 05:02:09 +10:00
|
|
|
extern crate crossterm;
|
|
|
|
|
2019-04-11 07:46:30 +10:00
|
|
|
use crossterm::{style, AlternateScreen, ClearType, Color, Crossterm};
|
2019-04-29 06:20:43 +10:00
|
|
|
use std::{io, thread, time};
|
2018-07-02 06:40:07 +10:00
|
|
|
|
2019-04-13 22:44:31 +10:00
|
|
|
fn print_wait_screen() -> io::Result<()> {
|
2019-04-11 07:46:30 +10:00
|
|
|
let crossterm = Crossterm::new();
|
2018-08-15 05:40:07 +10:00
|
|
|
let terminal = crossterm.terminal();
|
|
|
|
let cursor = crossterm.cursor();
|
2018-08-03 20:01:04 +10:00
|
|
|
|
2019-04-13 22:44:31 +10:00
|
|
|
terminal.clear(ClearType::All)?;
|
|
|
|
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: ",
|
2019-04-13 22:44:31 +10:00
|
|
|
)?;
|
2018-06-14 05:02:09 +10:00
|
|
|
// print some progress example.
|
2018-07-02 06:43:43 +10:00
|
|
|
for i in 1..5 {
|
2018-06-14 05:02:09 +10:00
|
|
|
// print the current counter at the line of `Seconds to Go: {counter}`
|
2019-04-13 22:44:31 +10:00
|
|
|
cursor.goto(10, 2)?;
|
2019-04-11 07:46:30 +10:00
|
|
|
println!(
|
|
|
|
"{}",
|
|
|
|
style(format!("{} of the 5 items processed", i))
|
|
|
|
.with(Color::Red)
|
|
|
|
.on(Color::Blue)
|
|
|
|
);
|
2018-06-14 05:02:09 +10:00
|
|
|
|
|
|
|
// 1 second delay
|
|
|
|
thread::sleep(time::Duration::from_secs(1));
|
|
|
|
}
|
2019-04-13 22:44:31 +10:00
|
|
|
|
|
|
|
Ok(())
|
2018-06-14 05:02:09 +10:00
|
|
|
}
|
|
|
|
|
2018-08-14 05:04:07 +10:00
|
|
|
/// print wait screen on alternate screen, then switch back.
|
2019-04-13 22:44:31 +10:00
|
|
|
pub fn print_wait_screen_on_alternate_window() -> io::Result<()> {
|
|
|
|
if let Ok(_alternate) = AlternateScreen::to_alternate(false) {
|
|
|
|
print_wait_screen()?;
|
2018-08-12 22:51:08 +10:00
|
|
|
}
|
2019-04-13 22:44:31 +10:00
|
|
|
|
|
|
|
Ok(())
|
2018-07-02 06:43:43 +10:00
|
|
|
}
|
2019-01-28 07:16:14 +11:00
|
|
|
|
|
|
|
fn main() {
|
2019-04-13 22:44:31 +10:00
|
|
|
print_wait_screen_on_alternate_window().unwrap();
|
2019-04-11 07:46:30 +10:00
|
|
|
}
|