small software-rendered rust tty
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs index 41c9153..ed4d160 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,11 @@ #![feature( - super_let, debug_closure_helpers, const_trait_impl, generic_assert, deadline_api, deref_patterns, generic_const_exprs, - guard_patterns, impl_trait_in_bindings, - if_let_guard, import_trait_associated_functions )] #![allow(incomplete_features)] @@ -60,12 +57,14 @@ fn spawn(shell: &str) -> Result<(OwnedFd, Pid)> { } } -fn read(fd: BorrowedFd) -> Option<Vec<u8>> { +#[cfg(target_family = "unix")] +pub fn read(fd: BorrowedFd) -> Option<Vec<u8>> { let mut x = [0; 1 << 16]; let n = nix::unistd::read(fd, &mut x).ok()?; Some(x[..n].to_vec()) } -fn write(fd: BorrowedFd, x: &[u8]) -> Result<()> { +#[cfg(target_family = "unix")] +pub fn write(fd: BorrowedFd, x: &[u8]) -> anyhow::Result<()> { let n = nix::unistd::write(fd, x)?; anyhow::ensure!(n == x.len()); Ok(()) @@ -106,7 +105,7 @@ fn main() -> Result<()> { let mut b = keyboard::Board::new(); while let Ok((k, s)) = krx.recv() { let x = b.rx(k, s); - write(pty1.as_fd(), &x).unwrap(); + pattypan::write(pty1.as_fd(), &x).unwrap(); } }); @@ -115,7 +114,7 @@ fn main() -> Result<()> { std::thread::spawn(move || { loop { - if let Some(x) = read(pty2.as_fd()) { + if let Some(x) = pattypan::read(pty2.as_fd()) { ttx.send(x).unwrap(); } sleep(Duration::from_millis(10)); @@ -231,14 +230,18 @@ fn main() -> Result<()> { } pub static FONT: LazyLock<FontRef<'static>> = LazyLock::new(|| { FontRef::from_index( - std::fs::read("/home/os/CascadiaCodeNF.ttf").unwrap().leak(), + std::fs::read("/home/os/pattypan/CascadiaCodeNF.ttf") + .unwrap() + .leak(), 0, ) .unwrap() }); pub static IFONT: LazyLock<FontRef<'static>> = LazyLock::new(|| { FontRef::from_index( - std::fs::read("/home/os/CascadiaCodeNFItalic.ttf").unwrap().leak(), + std::fs::read("/home/os/pattypan/CascadiaCodeNFItalic.ttf") + .unwrap() + .leak(), // &include_bytes!("/home/os/CascadiaCodeNFItalic.ttf")[..], 0, ) |