sway_command/commands/
mod.rs

1use derive_more::Display;
2
3mod config;
4pub use config::*;
5
6mod runtime;
7pub use runtime::*;
8
9mod standalone;
10pub use standalone::*;
11
12mod font;
13pub use font::*;
14
15#[derive(Display, Clone)]
16/// Workspace Selector
17pub enum Workspace {
18    /// Workspace name
19    #[display(fmt = "_0")]
20    Name(WorkspaceName),
21    /// Also matches a workspace with the same number, even if it has a
22    /// different name
23    #[display(fmt = "number _0")]
24    Number(WorkspaceName),
25    /// Moves the focused container to the previous workspace on this output, or
26    /// if no workspaces remain, the previous output
27    #[display(fmt = "prev")]
28    Prev,
29    /// Moves the focused container to the next workspace on this output, or if
30    /// no workspaces remain, the next output
31    #[display(fmt = "next")]
32    Next,
33    /// Moves the focused container to the current workspace
34    /// on this output
35    #[display(fmt = "current")]
36    Current,
37    /// Moves the focused container to the previous workspace on this output,
38    /// wrapping around if already at the first or last workspace
39    #[display(fmt = "prev_on_output")]
40    PrevOnOutput,
41    /// Moves the focused container to the next workspace on this output,
42    /// wrapping around if already at the first or last workspace
43    #[display(fmt = "next_on_output")]
44    NextOnOutput,
45    /// Moves the focused container to previously focused workspace
46    #[display(fmt = "back_and_forth")]
47    BackAndForth,
48}
49
50#[derive(Display, Clone)]
51/// Name of a workspace
52pub enum WorkspaceName {
53    /// Name without additional index
54    Simple(String),
55    /// Name with index
56    #[display(fmt = "{_0}:{_1}")]
57    WithNumber(u32, String),
58}
59
60#[derive(Display, Clone)]
61/// Output Selector
62pub enum Output {
63    /// Next output in the specified direction
64    #[display(fmt = "up")]
65    Up,
66    /// Next output in the specified direction
67    #[display(fmt = "right")]
68    Right,
69    /// Next output in the specified direction
70    #[display(fmt = "down")]
71    Down,
72    /// Next output in the specified direction
73    #[display(fmt = "left")]
74    Left,
75    /// Currently focused output
76    #[display(fmt = "current")]
77    Current,
78    /// Named output
79    Name(String),
80}
81
82#[derive(Display, Clone)]
83/// Direction of Gaps
84#[allow(missing_docs)]
85pub enum GapsDirection {
86    #[display(fmt = "inner")]
87    Inner,
88    #[display(fmt = "outer")]
89    Outer,
90    #[display(fmt = "horizontal")]
91    Horizontal,
92    #[display(fmt = "vertical")]
93    Vertical,
94    #[display(fmt = "top")]
95    Top,
96    #[display(fmt = "right")]
97    Right,
98    #[display(fmt = "bottom")]
99    Bottom,
100    #[display(fmt = "left")]
101    Left,
102}
103
104#[derive(Display, Clone)]
105#[allow(missing_docs)]
106pub enum YesNo {
107    #[display(fmt = "yes")]
108    Yes,
109    #[display(fmt = "no")]
110    No,
111}
112
113#[derive(Display, Clone)]
114#[allow(missing_docs)]
115pub enum EnDisable {
116    #[display(fmt = "enable")]
117    Enable,
118    #[display(fmt = "disable")]
119    Disable,
120}
121
122#[derive(Display, Clone)]
123#[allow(missing_docs)]
124pub enum EnDisTog {
125    #[display(fmt = "enable")]
126    Enable,
127    #[display(fmt = "disable")]
128    Disable,
129    #[display(fmt = "toggle")]
130    Toggle,
131}
132
133fn when(condition: bool, then: &str) -> &str {
134    if condition {
135        then
136    } else {
137        ""
138    }
139}
140fn then_or_empty<T>(value: &Option<T>, then: fn(&T) -> String) -> String {
141    value.as_ref().map(then).unwrap_or_default()
142}
143
144fn to_string_or_empty(value: &Option<impl ToString>) -> String {
145    value.as_ref().map(ToString::to_string).unwrap_or_default()
146}
147
148fn separated(values: impl IntoIterator<Item = impl ToString>, seperator: impl ToString) -> String {
149    values
150        .into_iter()
151        .map(|v| v.to_string())
152        .collect::<Vec<String>>()
153        .join(&seperator.to_string())
154}