use std::collections::HashMap;
use std::path::PathBuf;
use crate::terminal::backend::SessionBackend;
use crate::terminal::error::SessionError;
use crate::terminal::pty::{PtyConfig, PtySession};
use crate::terminal::session::Session;
#[derive(Debug, Clone, Default)]
pub struct PtySessionBackend;
impl PtySessionBackend {
pub fn new() -> Self {
Self
}
}
impl SessionBackend for PtySessionBackend {
fn create_session(
&self,
argv: Vec<String>,
cast_path: PathBuf,
cwd: Option<String>,
env: HashMap<String, String>,
cols: u16,
rows: u16,
) -> Result<Box<dyn Session>, SessionError> {
let config = PtyConfig {
argv,
cwd: cwd.map(PathBuf::from),
env,
cast_path: (!cast_path.as_os_str().is_empty()).then_some(cast_path),
};
let mut session = PtySession::new(config, cols, rows)?;
session.spawn()?;
Ok(Box::new(session))
}
fn name(&self) -> &str {
"pty"
}
}