use std::fmt;
#[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>,
}
impl ClientFlags {
fn bool_to_flag<S: AsRef<str>>(flag_name: S, state: bool) -> String {
match state {
true => flag_name.as_ref().to_string(),
false => 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";
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(CLIENT_FLAG_ACTIVE_PANE, active_pane));
}
if let Some(ignore_size) = self.ignore_size {
v.push(Self::bool_to_flag(CLIENT_FLAG_IGNORE_SIZE, ignore_size));
}
if let Some(no_output) = self.no_output {
v.push(Self::bool_to_flag(CLIENT_FLAG_NO_OUTPUT, no_output));
}
if let Some(pause_after) = self.pause_after {
v.push(format!(
"{}={}",
Self::bool_to_flag(CLIENT_FLAG_PAUSE_AFTER, true),
pause_after
));
}
if let Some(read_only) = self.read_only {
v.push(Self::bool_to_flag(CLIENT_FLAG_READ_ONLY, read_only));
}
if let Some(wait_exit) = self.wait_exit {
v.push(Self::bool_to_flag(CLIENT_FLAG_WAIT_EXIT, wait_exit));
}
let s = v.join(",");
write!(f, "{}", s)
}
}