aboutsummaryrefslogtreecommitdiff
path: root/crates/dinggerd/src/tmux.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/dinggerd/src/tmux.rs')
-rw-r--r--crates/dinggerd/src/tmux.rs31
1 files changed, 24 insertions, 7 deletions
diff --git a/crates/dinggerd/src/tmux.rs b/crates/dinggerd/src/tmux.rs
index b743256..510c54b 100644
--- a/crates/dinggerd/src/tmux.rs
+++ b/crates/dinggerd/src/tmux.rs
@@ -32,6 +32,8 @@ pub struct Pane {
pub written_importance: String,
pub written_extension: String,
pub written_control: String,
+ /// The draft in the agent's input box, as one line.
+ pub written_draft: String,
}
@@ -115,14 +117,15 @@ pub fn list_panes() -> Result<Vec<Pane>, String> {
"#{@agent_session}\t",
"#{@dingger_importance}\t",
"#{@dingger_extension}\t",
- "#{@dingger_control}",
+ "#{@dingger_control}\t",
+ "#{@dingger_draft}",
);
let out = run_tmux(&["list-panes", "-a", "-F", format])?;
let mut panes: Vec<Pane> = Vec::new();
let mut process_tree = None;
for line in out.lines() {
let fields: Vec<&str> = line.split('\t').collect();
- if fields.len() < 22 {
+ if fields.len() < 23 {
continue;
}
let attended = fields[4] == "1" && fields[5] != "0";
@@ -167,6 +170,7 @@ pub fn list_panes() -> Result<Vec<Pane>, String> {
written_importance: fields[19].to_string(),
written_extension: fields[20].to_string(),
written_control: fields[21].to_string(),
+ written_draft: fields[22].to_string(),
});
}
Ok(panes)
@@ -242,20 +246,33 @@ pub fn set_pane_option(pane_id: &str, name: &str, value: &str) -> Result<(), Str
/// Set (`Some`) or unset (`None`) several pane options in one tmux command
/// list, applied as a unit.
pub fn set_pane_options(pane_id: &str, changes: &[(&str, Option<String>)]) -> Result<(), String> {
- let mut args: Vec<&str> = Vec::new();
+ let mut args: Vec<String> = Vec::new();
for (name, value) in changes {
if !args.is_empty() {
- args.push(";");
+ args.push(";".into());
}
match value {
- Some(value) => args.extend(["set-option", "-p", "-t", pane_id, name, value.as_str()]),
- None => args.extend(["set-option", "-p", "-u", "-t", pane_id, name]),
+ Some(value) => {
+ args.extend(["set-option", "-p", "-t", pane_id, name].map(String::from));
+ args.push(command_list_value(value));
+ }
+ None => args.extend(["set-option", "-p", "-u", "-t", pane_id, name].map(String::from)),
}
}
if args.is_empty() {
return Ok(());
}
- run_tmux(&args).map(|_| ())
+ run_tmux(&args.iter().map(String::as_str).collect::<Vec<_>>()).map(|_| ())
+}
+
+/// A value as an argument in a tmux command list: tmux ends a command at an
+/// argument ending in `;` (dropping it) unless it ends in `\;`, and free
+/// text (a name, a draft) may end in one.
+fn command_list_value(value: &str) -> String {
+ match value.strip_suffix(';') {
+ Some(rest) => format!("{rest}\\;"),
+ None => value.to_string(),
+ }
}
pub fn unset_pane_option(pane_id: &str, name: &str) -> Result<(), String> {