1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 16:36:18 +04:00
rCore/kernel/src/console.rs
2018-07-16 22:02:03 +08:00

26 lines
578 B
Rust

use core::ops::Deref;
use alloc::string::String;
use arch::io::getchar;
pub fn get_line() -> String {
let mut s = String::new();
loop {
let c = getchar();
match c {
'\u{7f}' /* '\b' */ => {
if s.pop().is_some() {
print!("\u{7f}");
}
}
' '...'\u{7e}' => {
s.push(c);
print!("{}", c);
}
'\n' | '\r' => {
print!("\n");
return s;
}
_ => {}
}
}
}