b717d306c3
When you want to work with the 'alternate screen' you can call the following functions: terminal::from_screen etc. Which will give you an instance to the back of the module you are calling it in. So instead of: let color = color(Screen::default()); let cursor = cursor(Screen::default()); let input = input(Screen::default()); let terminal = terminal(Screen::default()); You can do: let color = color(); let cursor = cursor(); let input = input(); let terminal = terminal();
46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
extern crate crossterm;
|
|
|
|
use crossterm::style::{Color, style};
|
|
use crossterm::terminal::{self, ClearType};
|
|
use crossterm::{Crossterm, Screen};
|
|
|
|
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();
|
|
|
|
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);
|
|
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.
|
|
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);
|
|
}
|
|
}
|