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
128
use crate::commands::constants::*;
use crate::TmuxCommand;
use std::borrow::Cow;
pub type PipeP<'a> = PipePane<'a>;
/// Pipe output sent by the program in target-pane to a shell command or vice versa
///
/// # Manual
///
/// tmux ^2.7:
/// ```text
/// pipe-pane [-IOo] [-t target-pane] [shell-command]
/// (alias: pipep)
/// ```
///
/// tmux ^1.2:
/// ```text
/// pipe-pane [-o] [-t target-pane] [shell-command]
/// (alias: pipep)
/// ```
///
/// tmux ^1.1:
/// ```text
/// pipe-pane [-o] [-t target-pane] [command]
/// (alias: pipep)
/// ```
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct PipePane<'a> {
/// `[-I]` - stdin is connected
#[cfg(feature = "tmux_2_7")]
pub stdout: bool,
/// `[-O]` - stdout is connected
#[cfg(feature = "tmux_2_7")]
pub stdin: bool,
/// `[-o]` - only open a new pipe if no previous pipe exists
#[cfg(feature = "tmux_1_1")]
pub open: bool,
/// `[-t target-pane]` - target-pane
#[cfg(feature = "tmux_1_1")]
pub target_pane: Option<Cow<'a, str>>,
/// `[shell-command]` - shell-command
#[cfg(feature = "tmux_1_2")]
pub shell_command: Option<Cow<'a, str>>,
}
impl<'a> PipePane<'a> {
pub fn new() -> Self {
Default::default()
}
/// `[-I]` - stdin is connected
#[cfg(feature = "tmux_2_7")]
pub fn stdout(mut self) -> Self {
self.stdout = true;
self
}
/// `[-O]` - stdout is connected
#[cfg(feature = "tmux_2_7")]
pub fn stdin(mut self) -> Self {
self.stdin = true;
self
}
/// `[-o]` - only open a new pipe if no previous pipe exists
#[cfg(feature = "tmux_1_1")]
pub fn open(mut self) -> Self {
self.open = true;
self
}
/// `[-t target-pane]` - target-pane
#[cfg(feature = "tmux_1_1")]
pub fn target_pane<S: Into<Cow<'a, str>>>(mut self, target_pane: S) -> Self {
self.target_pane = Some(target_pane.into());
self
}
/// `[shell-command]` - shell-command
#[cfg(feature = "tmux_1_2")]
pub fn shell_command<S: Into<Cow<'a, str>>>(mut self, shell_command: S) -> Self {
self.shell_command = Some(shell_command.into());
self
}
pub fn build(self) -> TmuxCommand<'a> {
let mut cmd = TmuxCommand::new();
cmd.name(PIPE_PANE);
// `[-I]` - stdin is connected
#[cfg(feature = "tmux_2_7")]
if self.stdout {
cmd.push_flag(I_UPPERCASE_KEY);
}
// `[-O]` - stdout is connected
#[cfg(feature = "tmux_2_7")]
if self.stdin {
cmd.push_flag(O_UPPERCASE_KEY);
}
// `[-o]` - only open a new pipe if no previous pipe exists
#[cfg(feature = "tmux_1_1")]
if self.open {
cmd.push_flag(O_LOWERCASE_KEY);
}
// `[-t target-pane]` - target-pane
#[cfg(feature = "tmux_1_1")]
if let Some(target_pane) = self.target_pane {
cmd.push_option(T_LOWERCASE_KEY, target_pane);
}
// `[shell-command]` - shell-command
#[cfg(feature = "tmux_1_2")]
if let Some(shell_command) = self.shell_command {
cmd.push_param(shell_command);
}
cmd
}
}