use std::time::Duration;
use async_trait::async_trait;
use tokio::sync::mpsc;
use crate::error::IsolatorError;
#[derive(Debug, Clone, Default)]
pub struct IsolationOpts {
pub capture_stdout: bool,
pub capture_stderr: bool,
pub grace: Option<Duration>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ExitStatus {
pub code: Option<i32>,
pub success: bool,
}
impl ExitStatus {
pub fn ok() -> Self {
Self { code: Some(0), success: true }
}
pub fn from_code(code: i32) -> Self {
Self { code: Some(code), success: code == 0 }
}
}
#[async_trait]
pub trait ProcessHandle: Send {
fn take_stdout(&mut self) -> Option<mpsc::Receiver<Vec<u8>>>;
fn take_stderr(&mut self) -> Option<mpsc::Receiver<Vec<u8>>>;
fn take_stdin(&mut self) -> Option<mpsc::Sender<Vec<u8>>>;
fn is_pty(&self) -> bool;
async fn resize_pty(&mut self, cols: u16, rows: u16) -> Result<(), IsolatorError>;
async fn kill(&mut self) -> Result<(), IsolatorError>;
async fn wait(&mut self) -> Result<ExitStatus, IsolatorError>;
}