1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/ableos/src/stdio.rs

44 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(())
}
}
}
pub fn read(&mut self) {
todo!();
}
}