2018-06-14 05:02:09 +10:00
|
|
|
extern crate crossterm;
|
|
|
|
|
2018-06-17 04:10:51 +10:00
|
|
|
use crossterm::Context;
|
2018-06-14 05:02:09 +10:00
|
|
|
use crossterm::screen::AlternateScreen;
|
|
|
|
use crossterm::cursor::cursor;
|
|
|
|
use crossterm::terminal::{self, ClearType};
|
|
|
|
|
|
|
|
use std::io::{Write, stdout};
|
|
|
|
use std::{time, thread};
|
2018-06-23 05:04:30 +10:00
|
|
|
use std::rc::Rc;
|
2018-06-14 05:02:09 +10:00
|
|
|
|
|
|
|
use crossterm::raw::IntoRawMode;
|
|
|
|
|
2018-05-20 22:08:14 +10:00
|
|
|
// raw screen is not working correctly currently
|
2018-06-23 05:04:30 +10:00
|
|
|
fn print_wait_screen(context: Rc<Context>)
|
2018-06-14 05:02:09 +10:00
|
|
|
{
|
2018-06-23 05:04:30 +10:00
|
|
|
terminal::terminal(context.clone()).clear(ClearType::All);
|
2018-06-14 05:02:09 +10:00
|
|
|
|
2018-06-23 05:04:30 +10:00
|
|
|
let mut cursor = cursor(context.clone());
|
2018-06-17 04:10:51 +10:00
|
|
|
cursor.goto(0,0).print("Welcome to the wait screen.");
|
|
|
|
cursor.goto(0,1).print("Please wait a few seconds until we arrive back at the main screen.");
|
|
|
|
cursor.goto(0,2).print("Progress: ");
|
2018-06-14 05:02:09 +10:00
|
|
|
|
|
|
|
// print some progress example.
|
|
|
|
for i in 1..5
|
2018-06-17 04:10:51 +10:00
|
|
|
{
|
|
|
|
// print the current counter at the line of `Seconds to Go: {counter}`
|
|
|
|
cursor.goto(10,2).print(format!("{} of the 5 items processed", i));
|
2018-06-14 05:02:09 +10:00
|
|
|
|
2018-06-17 04:10:51 +10:00
|
|
|
// 1 second delay
|
|
|
|
thread::sleep(time::Duration::from_secs(1));
|
|
|
|
}
|
2018-06-14 05:02:09 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn print_wait_screen_on_alternate_window()
|
|
|
|
{
|
2018-06-17 04:10:51 +10:00
|
|
|
let context = Context::new();
|
2018-06-14 05:02:09 +10:00
|
|
|
|
|
|
|
// create scope. If this scope ends the screen will be switched back to mainscreen.
|
2018-06-17 04:10:51 +10:00
|
|
|
// because `AlternateScreen` switches back to main screen when going out of scope.
|
2018-06-14 05:02:09 +10:00
|
|
|
{
|
2018-06-17 04:10:51 +10:00
|
|
|
// create new alternate screen instance this call is also switching the screen to alternate screen.
|
|
|
|
// then convert the output of the program to raw mode.
|
|
|
|
// then print the wait screen on the alternate screen in raw mode.
|
2018-06-23 05:04:30 +10:00
|
|
|
let mut screen = AlternateScreen::from(context.clone());
|
|
|
|
let alternate_screen = screen.into_raw_mode(context.clone());
|
2018-06-14 05:02:09 +10:00
|
|
|
|
2018-06-17 04:10:51 +10:00
|
|
|
// Print the wait screen.
|
2018-06-23 05:04:30 +10:00
|
|
|
print_wait_screen(context.clone());
|
2018-06-14 05:02:09 +10:00
|
|
|
|
2018-06-17 04:10:51 +10:00
|
|
|
screen.flush();
|
2018-06-14 05:02:09 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
println!("Whe are back at the main screen");
|
|
|
|
}
|