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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use super::tmux_interface::*;
use super::tmux_interface_error::TmuxInterfaceError;
use std::process::Output;
#[derive(Default)]
pub struct IfShell<'a> {
pub backgroud: Option<bool>,
pub not_execute: Option<bool>,
pub target_pane: Option<&'a str>,
pub shell_command: &'a str,
pub first_command: &'a str,
pub second_command: Option<&'a str>
}
impl<'a> IfShell<'a> {
pub fn new() -> Self {
Default::default()
}
}
impl<'a> TmuxInterface<'a> {
const CLOCK_MODE: &'static str = "clock-mode";
const IF_SHELL: &'static str = "if-shell";
const LOCK_SERVER: &'static str = "lock-server";
const RUN_SHELL: &'static str = "run-shell";
const WAIT_FOR: &'static str = "wait-for";
pub fn clock_mode(&self, target_pane: Option<&str>) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::CLOCK_MODE, &args)?;
Ok(output)
}
pub fn if_shell(&self, if_shell: &IfShell) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if if_shell.backgroud.unwrap_or(false) { args.push(b_KEY); }
if if_shell.not_execute.unwrap_or(false) { args.push(F_KEY); }
if_shell.target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
args.push(if_shell.shell_command);
args.push(if_shell.first_command);
if_shell.second_command.and_then(|s| Some(args.push(&s)));
let output = self.subcommand(TmuxInterface::IF_SHELL, &args)?;
Ok(output)
}
pub fn lock_server(&self) -> Result<Output, TmuxInterfaceError> {
let output = self.subcommand(TmuxInterface::LOCK_SERVER, &[])?;
Ok(output)
}
pub fn run_shell(&self,
backgroud: Option<bool>,
target_pane: Option<&str>,
shell_command: &str
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if backgroud.unwrap_or(false) { args.push(b_KEY); }
target_pane.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
args.push(shell_command);
let output = self.subcommand(TmuxInterface::RUN_SHELL, &args)?;
Ok(output)
}
pub fn wait_for(&self,
lock: Option<bool>,
prevent_exit: Option<bool>,
unlock: Option<bool>,
channel: &str
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if lock.unwrap_or(false) { args.push(L_KEY); }
if prevent_exit.unwrap_or(false) { args.push(S_KEY); }
if unlock.unwrap_or(false) { args.push(U_KEY); }
args.push(channel);
let output = self.subcommand(TmuxInterface::WAIT_FOR, &args)?;
Ok(output)
}
}