small software-rendered rust tty
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a22dde3..749fabe 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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(())
}