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

62 lines
1.7 KiB
Rust
Raw Normal View History

2022-03-16 09:38:47 -05:00
use {
2022-08-08 12:07:43 -05:00
crate::devices::Device::{Block, Character, Vterm},
2022-03-16 09:38:47 -05:00
core::fmt::{Arguments, Error, Write},
2022-08-08 12:07:43 -05:00
kernel::device_interface::CharacterDevice,
2022-03-16 09:38:47 -05:00
};
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 {
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-08-08 12:07:43 -05:00
Block(_) => todo!(),
}
}
2022-04-11 17:23:11 -05:00
pub fn read(&mut self) {
2022-04-19 02:15:45 -05:00
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();
dev.read_char().map(|c| buf.push(c));
println!("{}", buf);
}
Vterm(vterm) => {
let mut buf = String::new();
vterm.read_char().map(|c| buf.push(c));
println!("{}", buf);
}
2022-08-08 12:07:43 -05:00
Block(_) => todo!(),
2022-04-19 02:15:45 -05:00
}
}
}