mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-23 16:36:18 +04:00
26 lines
578 B
Rust
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;
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
} |