1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use super::tmux_interface::*;
use super::tmux_interface_error::TmuxInterfaceError;
use std::process::Output;
#[derive(Default)]
pub struct CommandPrompt<'a> {
pub one_keypress: Option<bool>,
pub on_input_change: Option<bool>,
pub inputs: Option<&'a str>,
pub prompts: Option<&'a str>,
pub target_client: Option<&'a str>,
pub template: Option<&'a str>,
}
impl<'a> CommandPrompt<'a> {
pub fn new() -> Self {
Default::default()
}
}
impl<'a> TmuxInterface<'a> {
const COMMAND_PROMPT: &'static str = "command-prompt";
const CONFIRM_BEFORE: &'static str = "confirm-before";
const DISPLAY_MESSAGE: &'static str = "display-message";
pub fn command_prompt(&self,
command_prompt: &CommandPrompt
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if command_prompt.one_keypress.unwrap_or(false) { args.push(_1_KEY); }
if command_prompt.on_input_change.unwrap_or(false) { args.push(i_KEY); }
command_prompt.inputs.and_then(|s| Some(args.extend_from_slice(&[I_KEY, &s])));
command_prompt.prompts.and_then(|s| Some(args.extend_from_slice(&[p_KEY, &s])));
command_prompt.target_client.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
command_prompt.template.and_then(|s| Some(args.push(&s)));
let output = self.subcommand(TmuxInterface::COMMAND_PROMPT, &args)?;
Ok(output)
}
pub fn confirm_before(&self,
prompt: Option<&str>,
target_client: Option<&str>,
command: &str
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
prompt.and_then(|s| Some(args.extend_from_slice(&[p_KEY, &s])));
target_client.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
args.push(command);
let output = self.subcommand(TmuxInterface::CONFIRM_BEFORE, &args)?;
Ok(output)
}
pub fn display_message(&self,
print: Option<bool>,
target_client: Option<&str>,
target_pane: Option<&str>,
message: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if print.unwrap_or(false) { args.push(p_KEY); }
target_client.and_then(|s| Some(args.extend_from_slice(&[c_KEY, s])));
target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, s])));
message.and_then(|s| Some(args.push(&s)));
let output = self.subcommand(TmuxInterface::DISPLAY_MESSAGE, &args)?;
Ok(output)
}
}