Use liner to get username

This commit is contained in:
Jeremy Soller
2017-01-12 19:12:59 -07:00
parent ccae9c0b0a
commit 2fdef17559
2 changed files with 9 additions and 8 deletions
+1
View File
@@ -27,6 +27,7 @@ name = "sudo"
path = "src/bin/sudo.rs"
[dependencies]
liner = "0.1"
rand = "0.3"
redox_syscall = { git = "https://github.com/redox-os/syscall.git" }
termion = "1.1"
+8 -8
View File
@@ -1,3 +1,6 @@
#![deny(warnings)]
extern crate liner;
extern crate termion;
extern crate userutils;
@@ -11,10 +14,7 @@ use termion::input::TermRead;
use userutils::Passwd;
pub fn main() {
let stdin = io::stdin();
let mut stdin = stdin.lock();
let stdout = io::stdout();
let mut stdout = stdout.lock();
let mut stdout = io::stdout();
if let Ok(mut issue) = File::open("/etc/issue") {
io::copy(&mut issue, &mut stdout).unwrap();
@@ -22,11 +22,11 @@ pub fn main() {
}
loop {
stdout.write_all(b"\x1B[1mredox login:\x1B[0m ").unwrap();
let _ = stdout.flush();
let user = (&mut stdin as &mut Read).read_line().unwrap().unwrap_or(String::new());
let user = liner::Context::new().read_line("\x1B[1mredox login:\x1B[0m ", &mut |_| {}).unwrap();
if ! user.is_empty() {
let stdin = io::stdin();
let mut stdin = stdin.lock();
let mut passwd_string = String::new();
File::open("/etc/passwd").unwrap().read_to_string(&mut passwd_string).unwrap();