termion/examples/read.rs

24 lines
523 B
Rust
Raw Normal View History

extern crate libterm;
use libterm::ReadExt;
use std::io::{Write, stdout, stdin};
fn main() {
let stdout = stdout();
let mut stdout = stdout.lock();
2016-03-08 07:51:34 +00:00
let stdin = stdin();
let mut stdin = stdin.lock();
stdout.write(b"password: ").unwrap();
stdout.flush().unwrap();
2016-03-07 21:19:35 +00:00
let pass = stdin.read_passwd(&mut stdout);
2016-03-08 07:51:34 +00:00
if let Ok(Some(pass)) = pass {
stdout.write(pass.as_bytes()).unwrap();
stdout.write(b"\n").unwrap();
} else {
stdout.write(b"Error\n").unwrap();
}
}