mod async_adapter;
mod native;
pub use async_adapter::{AsyncPtyReader, AsyncPtyWriter};
pub use native::{default_shell, NativePty, SpawnedShell};
use std::io::{Read, Write};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PtySize {
pub rows: u16,
pub cols: u16,
}
impl PtySize {
pub fn new(rows: u16, cols: u16) -> Self {
Self { rows, cols }
}
}
impl Default for PtySize {
fn default() -> Self {
Self { rows: 24, cols: 80 }
}
}
pub struct PtyHandle<R: Read + Send, W: Write + Send> {
pub reader: R,
pub writer: W,
pub pid: u32,
_pty: Box<dyn std::any::Any + Send>,
}
impl<R: Read + Send, W: Write + Send> PtyHandle<R, W> {
pub fn new(reader: R, writer: W, pid: u32, pty: Box<dyn std::any::Any + Send>) -> Self {
Self {
reader,
writer,
pid,
_pty: pty,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_pty_size_default() {
let size = PtySize::default();
assert_eq!(size.rows, 24);
assert_eq!(size.cols, 80);
}
#[test]
fn test_pty_size_new() {
let size = PtySize::new(40, 120);
assert_eq!(size.rows, 40);
assert_eq!(size.cols, 120);
}
#[test]
fn test_pty_size_equality() {
let size1 = PtySize::new(24, 80);
let size2 = PtySize::default();
assert_eq!(size1, size2);
let size3 = PtySize::new(30, 100);
assert_ne!(size1, size3);
}
}