cf_pty_process_alpha/
lib.rs1pub mod unix;
2
3use std::{io, process::ExitStatus};
4
5use async_trait::async_trait;
6use thiserror::Error;
7use tokio::io::{AsyncRead, AsyncWrite};
8
9#[derive(Error, Debug)]
10pub enum PtySystemError {
11 #[error("io error: {0}")]
12 IoError(io::Error),
13}
14
15pub struct Size {
16 pub cols: u16,
17 pub rows: u16,
18}
19
20pub struct PtySystemOptions {
21 pub raw_mode: bool,
22}
23
24impl Default for PtySystemOptions {
25 fn default() -> Self {
26 Self { raw_mode: false }
27 }
28}
29
30#[async_trait]
31pub trait Child {
32 async fn wait(self) -> io::Result<ExitStatus>;
33
34 async fn kill(&mut self) -> io::Result<()>;
35}
36
37#[async_trait]
38pub trait Master {
39 async fn size(&self) -> io::Result<Size>;
40 async fn resize(&self, size: Size) -> io::Result<()>;
41}
42
43pub trait PtySystem {
44 type Child: Child;
45 type Master: Master;
46 type MasterRead: AsyncRead;
47 type MasterWrite: AsyncWrite;
48
49 fn spawn(
50 command: tokio::process::Command,
51 options: PtySystemOptions,
52 ) -> Result<PtySystemInstance<Self>, PtySystemError>;
53}
54
55pub struct PtySystemInstance<P>
56where
57 P: PtySystem + ?Sized,
58{
59 pub child: P::Child,
60 pub master: P::Master,
61 pub read: P::MasterRead,
62 pub write: P::MasterWrite,
63}
64
65pub trait MasterRead: AsyncRead {}
66
67pub trait MasterWrite: AsyncWrite {}