small software-rendered rust tty
dont depend on winit-wayland
| -rw-r--r-- | Cargo.toml | 15 | ||||
| -rw-r--r-- | src/lib.rs | 18 | ||||
| -rw-r--r-- | src/main.rs | 21 | ||||
| -rw-r--r-- | src/term.rs | 8 |
4 files changed, 34 insertions, 28 deletions
@@ -4,10 +4,10 @@ version = "0.1.0" edition = "2024" [dependencies] -anstream = "0.6.18" -anyhow = "1.0.98" +anstream = "1.0.0" +anyhow = "1.0.103" array_chunks = "1.0.0" -atools = "0.1.6" +atools = "0.1.13" chumsky = { git = "https://github.com/zesterer/chumsky", version = "0.13.0", features = [ "nightly", ] } @@ -17,14 +17,13 @@ dsb = { git = "https://git.bendn.org/dsb" } fimg = { git = "https://git.bendn.org/fimg" } implicit-fn = "0.1.0" -libc = "0.2.172" +libc = "0.2.186" minifb = "0.28.0" -nix = { version = "0.30.1", features = ["process", "term"] } -parking_lot = "0.12.3" +nix = { version = "0.31.3", features = ["process", "term"] } +parking_lot = "0.12.5" serde = { version = "1.0.228", features = ["derive"] } -swash = "0.2.4" +swash = "0.2.9" winit = { version = "0.31.0-beta.2", default-features = false, features = ["wayland", "x11"] } -winit-wayland = "=0.31.0-beta.2" [profile.release] debug = 0 @@ -1,27 +1,27 @@ #![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)] -use std::os::fd::BorrowedFd; - -use anyhow::ensure; pub mod colors; mod keyboard; pub mod term; -fn write(fd: BorrowedFd, x: &[u8]) -> anyhow::Result<()> { +#[cfg(target_family = "unix")] +pub fn read(fd: std::os::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()) +} +#[cfg(target_family = "unix")] +pub fn write(fd: std::os::fd::BorrowedFd, x: &[u8]) -> anyhow::Result<()> { let n = nix::unistd::write(fd, x)?; - ensure!(n != x.len()); + anyhow::ensure!(n == x.len()); Ok(()) } 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, ) diff --git a/src/term.rs b/src/term.rs index f713d40..d34670d 100644 --- a/src/term.rs +++ b/src/term.rs @@ -1,5 +1,4 @@ use std::ops::Not; -use std::os::fd::BorrowedFd; mod cells; use cells::*; use ctlfun::Parameter::*; @@ -80,7 +79,11 @@ impl Terminal { self.cells.cells().fill(DCELL); } #[implicit_fn::implicit_fn] - pub fn rx(&mut self, x: u8, pty: BorrowedFd<'_>) { + pub fn rx( + &mut self, + x: u8, + #[cfg(target_family = "unix")] pty: std::os::fd::BorrowedFd<'_>, + ) { match self.p.parse_byte(x) { Continue => {} Char(x) => { @@ -266,6 +269,7 @@ impl Terminal { end: b'n', .. }) => { + #[cfg(target_family = "unix")] super::write( pty, format!("\x1b[{};{}R", self.cursor.1, self.cursor.0) |