use std::fmt;
use std::num::NonZero;
use crate::pal::error::PalError;
use crate::pal::ids::PtyId;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) struct WindowSize {
pub cols: NonZero<u16>,
pub rows: NonZero<u16>,
}
pub(crate) const MAX_DIMENSION: u16 = i16::MAX.unsigned_abs();
impl WindowSize {
#[must_use]
pub(crate) const fn new(cols: u16, rows: u16) -> Option<Self> {
if cols > MAX_DIMENSION || rows > MAX_DIMENSION {
return None;
}
let (Some(cols), Some(rows)) = (NonZero::new(cols), NonZero::new(rows)) else {
return None;
};
Some(Self { cols, rows })
}
}
#[cfg_attr(test, mockall::automock)]
pub(crate) trait Pseudoconsole: Send + Sync + fmt::Debug + 'static {
fn create(&self, size: WindowSize) -> Result<PtyId, PalError>;
fn resize(&self, pty: PtyId, size: WindowSize) -> Result<(), PalError>;
fn write_input(&self, pty: PtyId, data: &[u8]) -> Result<(), PalError>;
fn read_output(&self, pty: PtyId) -> Result<Option<Vec<u8>>, PalError>;
fn finish(&self, pty: PtyId);
fn close(&self, pty: PtyId);
}