pub trait IntoAlternateScreen: Write + Sized {
    // Provided method
    fn into_alternate_screen(self) -> Result<AlternateScreen<Self>> { ... }
}
Expand description

Extension trait for writers, providing the into_alternate_screen function.

Provided Methods§

source

fn into_alternate_screen(self) -> Result<AlternateScreen<Self>>

Switch the terminal controlled by this writer to use the alternate screen. The terminal will be restored to the main screen when the AlternateScreen returned by this function is dropped.

Examples found in repository?
examples/alternate_screen.rs (line 9)
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    {
        let mut screen = stdout().into_alternate_screen().unwrap();
        write!(screen, "Welcome to the alternate screen.\n\nPlease wait patiently until we arrive back at the main screen in a about three seconds.").unwrap();
        screen.flush().unwrap();

        thread::sleep(time::Duration::from_secs(3));
    }

    println!("Phew! We are back.");
}
More examples
Hide additional examples
examples/alternate_screen_raw.rs (line 19)
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() {
    let stdin = stdin();
    let mut screen = stdout().into_raw_mode().unwrap().into_alternate_screen().unwrap();
    write!(screen, "{}", termion::cursor::Hide).unwrap();
    write_alt_screen_msg(&mut screen);

    screen.flush().unwrap();

    for c in stdin.keys() {
        match c.unwrap() {
            Key::Char('q') => break,
            Key::Char('1') => {
                write!(screen, "{}", ToMainScreen).unwrap();
            }
            Key::Char('2') => {
                write!(screen, "{}", ToAlternateScreen).unwrap();
                write_alt_screen_msg(&mut screen);
            }
            _ => {}
        }
        screen.flush().unwrap();
    }
    write!(screen, "{}", termion::cursor::Show).unwrap();
}

Object Safety§

This trait is not object safe.

Implementors§