use std::collections::HashMap;
use std::path::PathBuf;
use std::time::Duration;
use crate::terminal::backend::SessionBackend;
use crate::terminal::error::SessionError;
use crate::terminal::session::Session;
pub struct PluginSessionBackend {
pub argv: Vec<String>,
pub timeout: Duration,
}
impl PluginSessionBackend {
pub fn new(argv: Vec<String>) -> Self {
Self {
argv,
timeout: Duration::from_secs(30),
}
}
pub fn with_timeout(argv: Vec<String>, timeout: Duration) -> Self {
Self { argv, timeout }
}
}
impl SessionBackend for PluginSessionBackend {
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 _ = &self.argv;
let session =
crate::terminal::inmemory::InMemorySession::new(argv.clone(), cast_path, cols, rows);
let mut s = session;
s.feed(&format!(
"[plugin:{} cwd={:?} env={} keys]",
self.argv.join(" "),
cwd,
env.len()
));
Ok(Box::new(s))
}
fn name(&self) -> &str {
"custom"
}
}