85 lines
2.6 KiB
Rust
85 lines
2.6 KiB
Rust
pub use crate::drivers::io::{
|
|
ascii::{_print, _print_err, _print_log},
|
|
print, print_log, printerr, println, println_log, printlnerr,
|
|
serial::_serial_write,
|
|
serial_print, serial_println,
|
|
};
|
|
|
|
pub mod stdin {
|
|
use alloc::string::String;
|
|
|
|
use crate::drivers::io::{
|
|
ascii::WRITER,
|
|
keyboard::{KeyStroke, get_keystroke_async, get_keystroke_optional},
|
|
};
|
|
|
|
/// Reads a line of input from standard input asynchronously, returning a `String` containing
|
|
/// the input line. Does not include the newline character at the end of the line.
|
|
///
|
|
/// If the user presses the abort key (usually Ctrl+C), the returned string will be empty.
|
|
///
|
|
/// This function is currently unimplemented.
|
|
pub async fn read_line() -> String {
|
|
let mut writer = WRITER.lock();
|
|
|
|
let mut buff = String::new();
|
|
loop {
|
|
match get_keystroke_async().await {
|
|
KeyStroke::Char(c) => match c {
|
|
'\n' => {
|
|
writer.write_glyph(c as u8);
|
|
return buff;
|
|
}
|
|
'\r' => {
|
|
writer.write_glyph(c as u8);
|
|
return buff;
|
|
}
|
|
'\x08' => {
|
|
if !buff.is_empty() {
|
|
buff.pop();
|
|
writer.backspace();
|
|
}
|
|
}
|
|
|
|
c => {
|
|
writer.write_glyph(c as u8);
|
|
buff.push(c)
|
|
}
|
|
},
|
|
KeyStroke::Enter => {
|
|
writer.write_glyph(b'\n');
|
|
return buff;
|
|
}
|
|
KeyStroke::Backspace => {
|
|
if !buff.is_empty() {
|
|
buff.pop();
|
|
writer.backspace();
|
|
}
|
|
}
|
|
_ => continue,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Reads a character from standard input and blocks the current task until a character is
|
|
/// available.
|
|
///
|
|
/// # Note
|
|
///
|
|
/// This function is not yet implemented.
|
|
pub async fn async_keystroke() -> KeyStroke {
|
|
get_keystroke_async().await
|
|
}
|
|
|
|
/// Attempt to read a character from standard input without blocking the current task.
|
|
///
|
|
/// If no character is available, returns `None`.
|
|
///
|
|
/// # Note
|
|
///
|
|
/// This function is not yet implemented.
|
|
pub fn keystroke() -> Option<KeyStroke> {
|
|
get_keystroke_optional()
|
|
}
|
|
}
|