Better virtual file system, keyboard through MMIO&VirtIO
This commit is contained in:
73
src/tty.rs
Normal file
73
src/tty.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
use core::cell::RefCell;
|
||||
|
||||
use alloc::{boxed::Box, rc::Rc};
|
||||
use io::{IoBase, Read, Seek, Write};
|
||||
|
||||
use crate::{
|
||||
virtual_console::VirtualConsole,
|
||||
virtual_fs::{VirtualFileSystem, VirtualNode},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Tty {
|
||||
console: Rc<RefCell<VirtualConsole>>,
|
||||
}
|
||||
|
||||
impl Tty {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
console: RefCell::new(VirtualConsole::new()).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct TtyNode {
|
||||
console: Rc<RefCell<VirtualConsole>>,
|
||||
}
|
||||
|
||||
impl VirtualFileSystem for Tty {
|
||||
fn open(
|
||||
&mut self,
|
||||
path: &bffs::path::Path,
|
||||
) -> Result<alloc::boxed::Box<dyn crate::virtual_fs::VirtualNode + '_>, ()> {
|
||||
if !path.is_empty() {
|
||||
Err(())
|
||||
} else {
|
||||
Ok(Box::new(TtyNode {
|
||||
console: self.console.clone(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IoBase for TtyNode {
|
||||
type Error = ();
|
||||
}
|
||||
|
||||
impl Read for TtyNode {
|
||||
fn read(&mut self, _buf: &mut [u8]) -> Result<usize, Self::Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Seek for TtyNode {
|
||||
fn seek(&mut self, _pos: io::SeekFrom) -> Result<u64, Self::Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Write for TtyNode {
|
||||
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
|
||||
self.console
|
||||
.borrow_mut()
|
||||
.write_str(str::from_utf8(buf).unwrap());
|
||||
Ok(buf.len())
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> Result<(), Self::Error> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtualNode for TtyNode {}
|
||||
Reference in New Issue
Block a user