#[cfg(feature = "tmux_2_9a")]
use std::fmt;
#[cfg(feature = "tmux_2_9a")]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct ClientFlags {
pub active_pane: Option<bool>,
pub ignore_size: Option<bool>,
pub no_output: Option<bool>,
pub pause_after: Option<usize>,
pub read_only: Option<bool>,
pub wait_exit: Option<bool>,
}
#[cfg(feature = "tmux_2_9a")]
impl ClientFlags {
fn bool_to_flag<S: AsRef<str>>(value: bool, flag_name: S) -> String {
if value {
flag_name.as_ref().to_string()
} else {
format!("!{}", flag_name.as_ref())
}
}
}
const CLIENT_FLAG_ACTIVE_PANE: &str = "active-pane";
const CLIENT_FLAG_IGNORE_SIZE: &str = "ignore-size";
const CLIENT_FLAG_NO_OUTPUT: &str = "no-output";
const CLIENT_FLAG_PAUSE_AFTER: &str = "pause-after";
const CLIENT_FLAG_READ_ONLY: &str = "read-only";
const CLIENT_FLAG_WAIT_EXIT: &str = "wait-exit";
#[cfg(feature = "tmux_2_9a")]
impl fmt::Display for ClientFlags {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut v = Vec::new();
if let Some(active_pane) = self.active_pane {
v.push(Self::bool_to_flag(active_pane, CLIENT_FLAG_ACTIVE_PANE));
}
if let Some(ignore_size) = self.ignore_size {
v.push(Self::bool_to_flag(ignore_size, CLIENT_FLAG_IGNORE_SIZE));
}
if let Some(no_output) = self.no_output {
v.push(Self::bool_to_flag(no_output, CLIENT_FLAG_NO_OUTPUT));
}
if let Some(pause_after) = self.pause_after {
v.push(format!(
"{}={}",
Self::bool_to_flag(true, CLIENT_FLAG_PAUSE_AFTER),
pause_after
));
}
if let Some(read_only) = self.read_only {
v.push(Self::bool_to_flag(read_only, CLIENT_FLAG_READ_ONLY));
}
if let Some(wait_exit) = self.wait_exit {
v.push(Self::bool_to_flag(wait_exit, CLIENT_FLAG_WAIT_EXIT));
}
let s = v.join(",");
write!(f, "{}", s)
}
}