tmux_interface/commands/clients_and_sessions/
source_file.rs1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4
5pub type Source<'a> = SourceFile<'a>;
6
7#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
41pub struct SourceFile<'a> {
42 #[cfg(feature = "tmux_3_2")]
44 pub expand: bool,
45
46 #[cfg(feature = "tmux_3_0")]
48 pub not_execute: bool,
49
50 #[cfg(feature = "tmux_3_0")]
52 pub quiet: bool,
53
54 #[cfg(feature = "tmux_3_0")]
56 pub verbose: bool,
57
58 #[cfg(feature = "tmux_3_4")]
60 pub target_pane: Option<Cow<'a, str>>,
61
62 #[cfg(feature = "tmux_0_8")]
64 pub path: Option<Cow<'a, str>>,
65}
66
67impl<'a> SourceFile<'a> {
68 pub fn new() -> Self {
69 Default::default()
70 }
71
72 #[cfg(feature = "tmux_3_2")]
74 pub fn expand(mut self) -> Self {
75 self.expand = true;
76 self
77 }
78
79 #[cfg(feature = "tmux_3_0")]
81 pub fn not_execute(mut self) -> Self {
82 self.not_execute = true;
83 self
84 }
85
86 #[cfg(feature = "tmux_3_0")]
88 pub fn quiet(mut self) -> Self {
89 self.quiet = true;
90 self
91 }
92
93 #[cfg(feature = "tmux_3_0")]
95 pub fn verbose(mut self) -> Self {
96 self.verbose = true;
97 self
98 }
99
100 #[cfg(feature = "tmux_3_4")]
102 pub fn target_pane<S: Into<Cow<'a, str>>>(mut self, target_pane: S) -> Self {
103 self.target_pane = Some(target_pane.into());
104 self
105 }
106
107 #[cfg(feature = "tmux_0_8")]
109 pub fn path<S: Into<Cow<'a, str>>>(mut self, path: S) -> Self {
110 self.path = Some(path.into());
111 self
112 }
113
114 pub fn build(self) -> TmuxCommand<'a> {
115 let mut cmd = TmuxCommand::new();
116
117 cmd.name(SOURCE_FILE);
118
119 #[cfg(feature = "tmux_3_2")]
121 if self.expand {
122 cmd.push_flag(F_UPPERCASE_KEY);
123 }
124
125 #[cfg(feature = "tmux_3_0")]
127 if self.not_execute {
128 cmd.push_flag(N_LOWERCASE_KEY);
129 }
130
131 #[cfg(feature = "tmux_3_0")]
133 if self.quiet {
134 cmd.push_flag(Q_LOWERCASE_KEY);
135 }
136
137 #[cfg(feature = "tmux_3_0")]
139 if self.verbose {
140 cmd.push_flag(V_LOWERCASE_KEY);
141 }
142
143 #[cfg(feature = "tmux_3_4")]
145 if let Some(target_pane) = self.target_pane {
146 cmd.push_option(T_LOWERCASE_KEY, target_pane);
147 }
148
149 #[cfg(feature = "tmux_0_8")]
151 if let Some(path) = self.path {
152 cmd.push_param(path);
153 }
154
155 cmd
156 }
157}