pub use runtime_portal::editor::{Lease, Request, Status, TEXT_BYTES, VERSION};
use std::io;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Failure {
Rejected,
Busy,
Retired,
Unknown,
}
pub trait Completion: Send {
fn send(&self, send: &mut dyn FnMut() -> io::Result<()>) -> Result<(), Failure>;
fn finish(self: Box<Self>, result: Result<(), Failure>);
}
#[derive(Clone)]
pub struct Snapshot {
pub lease: Lease,
pub can_undo: bool,
pub can_redo: bool,
pub transaction: u64,
}
#[cfg(target_os = "linux")]
struct Observe;
#[cfg(target_os = "linux")]
impl Completion for Observe {
fn send(&self, send: &mut dyn FnMut() -> io::Result<()>) -> Result<(), Failure> {
send().map_err(|_| Failure::Retired)
}
fn finish(self: Box<Self>, _result: Result<(), Failure>) {}
}
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "linux")]
pub use linux::{Client, Socket};
#[cfg(not(target_os = "linux"))]
mod unsupported;
#[cfg(not(target_os = "linux"))]
pub use unsupported::{Client, Socket};
pub const fn supported() -> bool {
cfg!(target_os = "linux")
}
pub fn read_finds_no_slave(result: &io::Result<usize>) -> bool {
match result {
Ok(read) => *read == 0 && cfg!(target_vendor = "apple"),
#[cfg(unix)]
Err(error) => error.raw_os_error() == Some(libc::EIO),
#[cfg(not(unix))]
Err(_) => false,
}
}
#[cfg(unix)]
pub fn validate_master(master: &std::fs::File) -> io::Result<()> {
#[cfg(target_os = "linux")]
{
use std::os::fd::AsRawFd;
let mut number = 0u32;
if unsafe { libc::ioctl(master.as_raw_fd(), libc::TIOCGPTN, &raw mut number) } != 0 {
return Err(io::Error::other(
"The ush PTY role is not a master terminal",
));
}
}
#[cfg(not(target_os = "linux"))]
let _ = master;
Ok(())
}