diff --git a/Cargo.lock b/Cargo.lock index 33c09a9..0e64bae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,7 +88,6 @@ version = "0.1.0" dependencies = [ "syslog_msg_ipc", "syslog_rpc", - "unicode_reader", ] [[package]] @@ -274,22 +273,6 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" -[[package]] -name = "unicode-segmentation" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" - -[[package]] -name = "unicode_reader" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d68d43b506d20b459657e0f0fe3bf0fdbac65b61cbcc2bff842fc6614a8dc179" -dependencies = [ - "smallvec", - "unicode-segmentation", -] - [[package]] name = "windows-targets" version = "0.52.6" diff --git a/Cargo.toml b/Cargo.toml index 1b6a41c..b8a13e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,3 @@ edition = "2021" [dependencies] syslog_msg_ipc = { version = "0.1.0", path = "../syslog/syslog_msg_ipc" } syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" } -unicode_reader = "1.0.2" diff --git a/src/main.rs b/src/main.rs index ef58e49..f2bcd93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,11 @@ -use std::{fs::File, io::{BufReader, Write}, os::mikros::{ipc, syscalls}, process::Command}; +use std::{ + fs::File, + io::{Read, Write}, + os::mikros::{ipc, syscalls}, + process::Command, +}; use syslog_rpc::Message; -use unicode_reader::CodePoints; struct SyslogMessageHandler { registered_devices: Vec, @@ -48,32 +52,29 @@ fn main() { .unwrap(); Command::new("/bin/ps2").spawn().unwrap(); + syslog_client + .send_text_message("init_phase2", "Starting PTY server") + .unwrap(); + Command::new("/bin/pty_server").spawn().unwrap(); + let mut msg_handler = SyslogMessageHandler::new(); - while !msg_handler - .registered_devices - .iter() - .any(|x| x == "kbd") - { + while !msg_handler.registered_devices.iter().any(|x| x == "kbd") { msg_handler.process_messages(); } - let kbd = BufReader::new(File::open("/dev/kbd").unwrap()); + let mut kbd = File::open("/dev/kbd").unwrap(); let mut display = File::open("/dev/bga0").unwrap(); - let mut line_buf = String::new(); + let mut pty = File::open("/dev/ptmx").unwrap(); - for ch in CodePoints::from(kbd) { - let Ok(ch) = ch else { - continue; - }; - write!(display, "{}", ch).unwrap(); - if ch == '\n' { - println!("Got line: {:?}", &line_buf); - line_buf.clear(); - } else if ch == '\u{8}' { - line_buf.pop(); - } else { - line_buf.push(ch); - } + Command::new("/bin/pts_tester").spawn().unwrap(); + + let mut kbd_buf = [0u8; 512]; + let mut pty_buf = [0u8; 512]; + loop { + let kbd_len = kbd.read(&mut kbd_buf).unwrap(); + let pty_len = pty.read(&mut pty_buf).unwrap(); + pty.write_all(&kbd_buf[..kbd_len]).unwrap(); + display.write_all(&pty_buf[..pty_len]).unwrap(); } }