fune/third_party/rust/termion/examples/simple.rs
Nathan Froyd 65e7b0bbd1 Bug 1485409 - update crates to dispense with winapi 0.2.8 requirement; r=glandium
winapi 0.2.8 is used by a number of crates in our dependency graph.  The
newest version of winapi is 0.3.4, which is a significant restructuring
and also more amenable to further development, e.g. adding AArch64
support.  This patch does the easy work of updating as many things as
possible to winapi 0.3.4 via a simple `cargo update`:

cargo update -p atty:0.2.2 -p fs2 -p msdos_time -p parking_lot_core -p aho-corasick

and then vendoring the results of those changes.
2018-08-28 21:37:30 -04:00

42 lines
1.1 KiB
Rust

extern crate termion;
use termion::color;
use termion::raw::IntoRawMode;
use std::io::{Read, Write, stdout, stdin};
fn main() {
// Initialize 'em all.
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let stdin = stdin();
let stdin = stdin.lock();
write!(stdout,
"{}{}{}yo, 'q' will exit.{}{}",
termion::clear::All,
termion::cursor::Goto(5, 5),
termion::style::Bold,
termion::style::Reset,
termion::cursor::Goto(20, 10))
.unwrap();
stdout.flush().unwrap();
let mut bytes = stdin.bytes();
loop {
let b = bytes.next().unwrap().unwrap();
match b {
// Quit
b'q' => return,
// Clear the screen
b'c' => write!(stdout, "{}", termion::clear::All),
// Set red color
b'r' => write!(stdout, "{}", color::Fg(color::Rgb(5, 0, 0))),
// Write it to stdout.
a => write!(stdout, "{}", a),
}
.unwrap();
stdout.flush().unwrap();
}
}