]>
Commit | Line | Data |
---|---|---|
abe05a73 XL |
1 | extern crate termion; |
2 | ||
3 | use termion::event::Key; | |
4 | use termion::input::TermRead; | |
5 | use termion::raw::IntoRawMode; | |
6 | use termion::screen::*; | |
7 | use std::io::{Write, stdout, stdin}; | |
8 | ||
9 | fn 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 | ||
17 | fn 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 | } |