mod standalone;
mod tmux_adapter;
pub use standalone::StandaloneAdapter;
pub use tmux_adapter::TmuxAdapter;
use anyhow::Result;
use crate::tmux::PaneInfo;
pub trait RuntimeAdapter: Send + Sync {
fn list_all_panes(&self) -> Result<Vec<PaneInfo>>;
fn list_panes(&self) -> Result<Vec<PaneInfo>>;
fn list_sessions(&self) -> Result<Vec<String>>;
fn is_available(&self) -> bool;
fn capture_pane(&self, target: &str) -> Result<String>;
fn capture_pane_full(&self, target: &str) -> Result<String> {
self.capture_pane(target)
}
fn capture_pane_plain(&self, target: &str) -> Result<String>;
fn get_pane_title(&self, target: &str) -> Result<String>;
fn get_cursor_position(&self, _target: &str) -> Result<Option<(u32, u32)>> {
Ok(None)
}
fn send_keys(&self, target: &str, keys: &str) -> Result<()>;
fn send_keys_literal(&self, target: &str, keys: &str) -> Result<()>;
fn send_text_and_enter(&self, target: &str, text: &str) -> Result<()>;
fn focus_pane(&self, target: &str) -> Result<()>;
fn kill_pane(&self, target: &str) -> Result<()>;
fn create_session(&self, _name: &str, _cwd: &str, _window_name: Option<&str>) -> Result<()> {
anyhow::bail!("session creation not supported by {} runtime", self.name())
}
fn new_window(&self, _session: &str, _cwd: &str, _window_name: Option<&str>) -> Result<String> {
anyhow::bail!("window creation not supported by {} runtime", self.name())
}
fn split_window(&self, _session: &str, _cwd: &str) -> Result<String> {
anyhow::bail!("window splitting not supported by {} runtime", self.name())
}
fn split_window_tiled(&self, session: &str, cwd: &str) -> Result<String> {
self.split_window(session, cwd)
}
fn select_layout(&self, _target: &str, _layout: &str) -> Result<()> {
Ok(()) }
fn count_panes(&self, _target: &str) -> Result<usize> {
Ok(0)
}
fn run_command(&self, _target: &str, _command: &str) -> Result<()> {
anyhow::bail!("command execution not supported by {} runtime", self.name())
}
fn run_command_wrapped(&self, _target: &str, _command: &str) -> Result<()> {
anyhow::bail!("wrapped command not supported by {} runtime", self.name())
}
fn get_current_location(&self) -> Result<(String, u32)> {
anyhow::bail!("current location not available in {} runtime", self.name())
}
fn name(&self) -> &str;
}