akern-gkgoat-fork/ableos/src/stdio.rs

45 lines
1.1 KiB
Rust
Raw Normal View History

2022-03-16 09:38:47 -05:00
use {
crate::devices::Device::{Character, Vterm},
2022-03-16 09:38:47 -05:00
core::fmt::{Arguments, Error, Write},
kernel::device_interface::character::CharacterDevice,
};
2022-03-16 09:38:47 -05:00
#[derive(Debug, Clone)]
pub struct StdIO {
2022-03-16 09:38:47 -05:00
device: String,
}
impl StdIO {
2022-03-16 09:38:47 -05:00
pub fn new(device: String) -> StdIO {
StdIO { device }
}
2022-03-16 09:38:47 -05:00
pub fn write(&mut self, args: Arguments) -> Result<(), Error> {
use crate::devices::DEVICE_TABLE;
let mut dt = DEVICE_TABLE.lock();
let key_device = dt.devices.get_mut(&self.device).unwrap();
match key_device {
Character(dev) => {
let mut buf = String::new();
write!(buf, "{}", args).unwrap();
for c in buf.chars() {
dev.write_char(c);
}
Ok(())
}
2022-03-16 09:38:47 -05:00
Vterm(vterm) => {
let mut buf = String::new();
write!(buf, "{}", args).unwrap();
for c in buf.chars() {
vterm.write_char(c);
}
Ok(())
}
}
}
2022-04-11 17:23:11 -05:00
pub fn read(&mut self) {
todo!();
}
}