forked from crossterm-rs/crossterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alternate_screen_dropped.rs
38 lines (35 loc) · 1.15 KB
/
alternate_screen_dropped.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
extern crate crossterm;
use self::crossterm::{Crossterm, Screen, ClearType};
use std::io::Read;
use std::{thread, time};
fn main() {
let raw_mode = true;
let screen = Screen::new(raw_mode);
let crossterm: Crossterm;
{
let alternate_screen = screen.enable_alternate_modes(raw_mode).unwrap();
crossterm = Crossterm::from_screen(&alternate_screen.screen);
}
// <-- Dropping alternate_screen here
let mut input = crossterm.input().read_async().bytes();
let terminal = crossterm.terminal();
let cursor = crossterm.cursor();
cursor.hide().unwrap();
loop {
terminal.clear(ClearType::All).unwrap();
cursor.goto(1, 1).unwrap();
match input.next() {
// These user inputs are not in raw mode
Some(ipt) => {
terminal.write(format!("{:?} <- Character pressed", ipt)).unwrap();
match ipt {
// Does not return to original screen
Ok(b'q') => break,
_ => {},
};
},
_ => {}
};
thread::sleep(time::Duration::from_millis(200));
}
}