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
use super::tmux_interface::*;
use super::tmux_interface_error::TmuxInterfaceError;
use std::process::Output;
#[derive(Default, Clone, Debug)]
pub struct SetHook<'a> {
pub append: Option<bool>,
pub global: Option<bool>,
pub run: Option<bool>,
pub unset: Option<bool>,
pub target_session: Option<&'a str>,
pub hook_name: &'a str,
pub command: &'a str
}
impl<'a> SetHook<'a> {
pub fn new() -> Self {
Default::default()
}
}
impl<'a> TmuxInterface<'a> {
const SET_HOOK: &'static str = "set-hook";
const SHOW_HOOK: &'static str = "show-hook";
pub fn set_hook(&self, set_hook: &SetHook) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if set_hook.append.unwrap_or(false) { args.push(a_KEY); }
if set_hook.global.unwrap_or(false) { args.push(g_KEY); }
if set_hook.run.unwrap_or(false) { args.push(R_KEY); }
if set_hook.unset.unwrap_or(false) { args.push(u_KEY); }
set_hook.target_session.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
args.push(set_hook.hook_name);
args.push(set_hook.command);
let output = self.subcommand(TmuxInterface::SET_HOOK, &args)?;
Ok(output)
}
pub fn show_hooks(&self,
global: Option<bool>,
target_session: Option<&str>
) -> Result<Output, TmuxInterfaceError> {
let mut args: Vec<&str> = Vec::new();
if global.unwrap_or(false) { args.push(g_KEY); }
target_session.and_then(|s| Some(args.extend_from_slice(&[t_KEY, &s])));
let output = self.subcommand(TmuxInterface::SHOW_HOOK, &args)?;
Ok(output)
}
}