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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
/// Structure for open the command prompt in a client
///
/// # Manual
///
/// tmux ^3.3:
/// ```text
/// command-prompt [-1bFikN] [-I inputs] [-p prompts] [-t target-client] [-T prompt-type] [template]
/// ```
///
/// tmux ^3.2:
/// ```text
/// command-prompt [-1ikNTW] [-I inputs] [-p prompts] [-t target-client] [template]
/// ```
///
/// tmux ^3.1:
/// ```text
/// command-prompt [-1ikN] [-I inputs] [-p prompts] [-t target-client] [template]
/// ```
///
/// tmux ^3.0:
/// ```text
/// command-prompt [-1Ni] [-I inputs] [-p prompts] [-t target-client] [template]
/// ```
///
/// tmux ^2.4:
/// ```text
/// command-prompt [-1i] [-I inputs] [-p prompts] [-t target-client] [template]
/// ```
///
/// tmux ^1.5:
/// ```text
/// command-prompt [-I inputs] [-p prompts] [-t target-client] [template]
/// ```
///
/// tmux ^1.0:
/// ```text
/// command-prompt [-p prompts] [-t target-client] [template]
/// ```
///
/// tmux ^0.8:
/// ```text
/// command-prompt [-t target-client] [template]
/// ```
#[macro_export]
macro_rules! command_prompt {
// `[-1]` - makes the prompt only accept one key press
(@cmd ($cmd:expr) -1, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.one_keypress()
}) $($tail)*)
}};
// `[-b]` - the prompt is shown in the background and the invoking client does not exit until it is dismissed
(@cmd ($cmd:expr) -b, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.background()
}) $($tail)*)
}};
// `[-F]` -
(@cmd ($cmd:expr) -F, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.expand_as_format()
}) $($tail)*)
}};
// `[-i]` execute the command every time the prompt input changes
(@cmd ($cmd:expr) -i, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.on_input_change()
}) $($tail)*)
}};
// `[-k]` - the key press is translated to a key name
(@cmd ($cmd:expr) -k, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.key_name()
}) $($tail)*)
}};
// `[-N]` - makes the prompt only accept numeric key presses
(@cmd ($cmd:expr) -N, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.numeric()
}) $($tail)*)
}};
// `[-T]` - tells tmux that the prompt is for a target which affects what completions are offered when Tab is pressed
(@cmd ($cmd:expr) -T, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.for_target()
}) $($tail)*)
}};
// `[-W]` - indicates the prompt is for a window.
(@cmd ($cmd:expr) -W, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.for_window()
}) $($tail)*)
}};
// `[-T prompt-type]` - tells tmux the prompt type. This affects what completions are offered when Tab is pressed
(@cmd ($cmd:expr) -T $prompt_type:expr, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.prompt_type($prompt_type)
}) $($tail)*)
}};
// `[-I inputs]` - comma-separated list of the initial text for each prompt
(@cmd ($cmd:expr) -I $inputs:expr, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.inputs($inputs)
}) $($tail)*)
}};
// `[-p prompts]` - prompts is a comma-separated list of prompts which are displayed in order
(@cmd ($cmd:expr) -p $prompts:expr, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.prompts($prompts)
}) $($tail)*)
}};
// `[-t target-client]` - target-client
(@cmd ($cmd:expr) -t $target_client:expr, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.target_client($target_client)
}) $($tail)*)
}};
// `[template]` - template
(@cmd ($cmd:expr) $template:expr, $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({
$cmd.template($template)
}) $($tail)*)
}};
//(@cmd ($cmd:expr) -$unknown:tt, $($tail:tt)*) => {{
//::std::compile_error!("unknown flag, option or parameter: {}", $unknown);
//}};
(@cmd ($cmd:expr)) => {{
$cmd
}};
() => {{
$crate::CommandPrompt::new()
}};
(($cmd:expr), $($tail:tt)*) => {{
$crate::command_prompt!(@cmd ($cmd) $($tail)*,)
}};
($($tail:tt)*) => {{
$crate::command_prompt!(@cmd ({ $crate::CommandPrompt::new() }) $($tail)*,)
}};
}
#[test]
fn command_prompt_macro() {
#[cfg(feature = "tmux_3_3")]
use crate::commands::PromptType;
use std::borrow::Cow;
// Structure for open the command prompt in a client
//
// # Manual
//
// tmux ^3.3:
// ```text
// command-prompt [-1bFikN] [-I inputs] [-p prompts] [-t target-client] [-T prompt-type] [template]
// ```
//
// tmux ^3.2:
// ```text
// command-prompt [-1ikNTW] [-I inputs] [-p prompts] [-t target-client] [template]
// ```
//
// tmux ^3.1:
// ```text
// command-prompt [-1ikN] [-I inputs] [-p prompts] [-t target-client] [template]
// ```
//
// tmux ^3.0:
// ```text
// command-prompt [-1Ni] [-I inputs] [-p prompts] [-t target-client] [template]
// ```
//
// tmux ^2.4:
// ```text
// command-prompt [-1i] [-I inputs] [-p prompts] [-t target-client] [template]
// ```
//
// tmux ^1.5:
// ```text
// command-prompt [-I inputs] [-p prompts] [-t target-client] [template]
// ```
//
// tmux ^1.0:
// ```text
// command-prompt [-p prompts] [-t target-client] [template]
// ```
//
// tmux ^0.8:
// ```text
// command-prompt [-t target-client] [template]
// ```
let command_prompt = command_prompt!();
#[cfg(feature = "tmux_2_4")]
let command_prompt = command_prompt!((command_prompt), -1);
#[cfg(feature = "tmux_2_4")]
let command_prompt = command_prompt!((command_prompt), -i);
#[cfg(feature = "tmux_3_1")]
let command_prompt = command_prompt!((command_prompt), -k);
#[cfg(feature = "tmux_3_1")]
let command_prompt = command_prompt!((command_prompt), -N);
#[cfg(all(feature = "tmux_3_2", not(feature = "tmux_3_3")))]
let command_prompt = command_prompt!((command_prompt), -T);
#[cfg(feature = "tmux_3_3")]
let command_prompt = command_prompt!((command_prompt), -T PromptType::Command);
#[cfg(feature = "tmux_3_2")]
let command_prompt = command_prompt!((command_prompt), -W);
#[cfg(feature = "tmux_1_5")]
let command_prompt = command_prompt!((command_prompt), -I "1");
#[cfg(feature = "tmux_1_0")]
let command_prompt = command_prompt!((command_prompt), -p "2");
#[cfg(feature = "tmux_0_8")]
let command_prompt = command_prompt!((command_prompt), -t "3");
#[cfg(feature = "tmux_0_8")]
let command_prompt = command_prompt!((command_prompt), "4");
let cmd = "command-prompt";
let mut s = Vec::new();
s.push(cmd);
#[cfg(feature = "tmux_2_4")]
s.push("-1");
#[cfg(feature = "tmux_2_4")]
s.push("-i");
#[cfg(feature = "tmux_3_1")]
s.push("-k");
#[cfg(feature = "tmux_3_1")]
s.push("-N");
#[cfg(all(feature = "tmux_3_2", not(feature = "tmux_3_3")))]
s.push("-T");
#[cfg(feature = "tmux_3_3")]
s.extend_from_slice(&["-T", "command"]);
#[cfg(feature = "tmux_3_2")]
s.push("-W");
#[cfg(feature = "tmux_1_5")]
s.extend_from_slice(&["-I", "1"]);
#[cfg(feature = "tmux_1_0")]
s.extend_from_slice(&["-p", "2"]);
#[cfg(feature = "tmux_0_8")]
s.extend_from_slice(&["-t", "3"]);
#[cfg(feature = "tmux_0_8")]
s.push("4");
let s: Vec<Cow<str>> = s.into_iter().map(|a| a.into()).collect();
let command_prompt = command_prompt.build().to_vec();
assert_eq!(command_prompt, s);
}