tmux_interface/commands/clients_and_sessions/
list_sessions.rs1use crate::commands::constants::*;
2use crate::TmuxCommand;
3use std::borrow::Cow;
4use std::marker::PhantomData;
5
6pub type Ls<'a> = ListSessions<'a>;
7
8#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
30pub struct ListSessions<'a> {
31    #[cfg(feature = "tmux_1_6")]
33    pub format: Option<Cow<'a, str>>,
34
35    #[cfg(feature = "tmux_3_4")]
37    pub filter: Option<Cow<'a, str>>,
38
39    _phantom_data: PhantomData<&'a ()>,
40}
41
42impl<'a> ListSessions<'a> {
43    pub fn new() -> Self {
44        Default::default()
45    }
46
47    #[cfg(feature = "tmux_1_6")]
49    pub fn format<S: Into<Cow<'a, str>>>(mut self, format: S) -> Self {
50        self.format = Some(format.into());
51        self
52    }
53
54    #[cfg(feature = "tmux_3_4")]
56    pub fn filter<S: Into<Cow<'a, str>>>(mut self, filter: S) -> Self {
57        self.filter = Some(filter.into());
58        self
59    }
60
61    pub fn build(self) -> TmuxCommand<'a> {
62        let mut cmd = TmuxCommand::new();
63
64        cmd.name(LIST_SESSIONS);
65
66        #[cfg(feature = "tmux_1_6")]
68        if let Some(format) = self.format {
69            cmd.push_option(F_UPPERCASE_KEY, format);
70        }
71
72        #[cfg(feature = "tmux_3_4")]
74        if let Some(filter) = self.filter {
75            cmd.push_option(F_LOWERCASE_KEY, filter);
76        }
77
78        cmd
79    }
80}