]> git.proxmox.com Git - rustc.git/blame - src/vendor/termion/examples/alternate_screen_raw.rs
New upstream version 1.31.0+dfsg1
[rustc.git] / src / vendor / termion / examples / alternate_screen_raw.rs
CommitLineData
abe05a73
XL
1extern crate termion;
2
3use termion::event::Key;
4use termion::input::TermRead;
5use termion::raw::IntoRawMode;
6use termion::screen::*;
7use std::io::{Write, stdout, stdin};
8
9fn write_alt_screen_msg<W: Write>(screen: &mut W) {
10 write!(screen, "{}{}Welcome to the alternate screen.{}Press '1' to switch to the main screen or '2' to switch to the alternate screen.{}Press 'q' to exit (and switch back to the main screen).",
11 termion::clear::All,
12 termion::cursor::Goto(1, 1),
13 termion::cursor::Goto(1, 3),
14 termion::cursor::Goto(1, 4)).unwrap();
15}
16
17fn main() {
18 let stdin = stdin();
19 let mut screen = AlternateScreen::from(stdout().into_raw_mode().unwrap());
20 write!(screen, "{}", termion::cursor::Hide).unwrap();
21 write_alt_screen_msg(&mut screen);
22
23 screen.flush().unwrap();
24
25 for c in stdin.keys() {
26 match c.unwrap() {
27 Key::Char('q') => break,
28 Key::Char('1') => {
29 write!(screen, "{}", ToMainScreen).unwrap();
30 }
31 Key::Char('2') => {
32 write!(screen, "{}", ToAlternateScreen).unwrap();
33 write_alt_screen_msg(&mut screen);
34 }
35 _ => {}
36 }
37 screen.flush().unwrap();
38 }
39 write!(screen, "{}", termion::cursor::Show).unwrap();
40}