diff options
Diffstat (limited to 'crates/dinggerd/src/tmux.rs')
| -rw-r--r-- | crates/dinggerd/src/tmux.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/crates/dinggerd/src/tmux.rs b/crates/dinggerd/src/tmux.rs index e833e3c..edd44aa 100644 --- a/crates/dinggerd/src/tmux.rs +++ b/crates/dinggerd/src/tmux.rs @@ -4,7 +4,6 @@ use std::process::Command; use detect_core::manifest::agent_state_label; use detect_core::{identify_agent, Agent, AgentState}; -use tracing::debug; #[derive(Debug, Clone)] pub struct Pane { @@ -25,6 +24,8 @@ pub struct Pane { /// The `@agent_state` user option previously written for this pane, /// read straight from the pane format. pub written_state: String, + /// The `@agent` user option (agent label) previously written, if any. + pub written_agent: String, } impl Pane { @@ -68,13 +69,14 @@ pub fn list_panes() -> Result<Vec<Pane>, String> { "#{session_attached}\t", "#{pane_start_command}\t", "#{pane_pid}\t", - "#{@agent_state}" + "#{@agent_state}\t", + "#{@agent}" ); let out = run_tmux(&["list-panes", "-a", "-F", format])?; let mut panes = Vec::new(); for line in out.lines() { let fields: Vec<&str> = line.split('\t').collect(); - if fields.len() < 10 { + if fields.len() < 11 { continue; } let current_command = fields[2].to_string(); @@ -101,6 +103,7 @@ pub fn list_panes() -> Result<Vec<Pane>, String> { session_attached: fields[6] != "0", agent, written_state: fields[9].to_string(), + written_agent: fields[10].to_string(), }); } Ok(panes) @@ -180,3 +183,10 @@ pub fn set_agent_state(pane_id: &str, state: AgentState) -> Result<(), String> { ]) .map(|_| ()) } + +/// Label the pane with the agent running in it, for tmux status-line and +/// menu-bar rendering; clears the label when the pane stops running one. +pub fn set_agent(pane_id: &str, agent: Option<Agent>) -> Result<(), String> { + let label = agent.map(detect_core::agent_label).unwrap_or(""); + run_tmux(&["set-option", "-p", "-t", pane_id, "@agent", label]).map(|_| ()) +} |
