bspc_rust_lib/bspc/node/
path.rs1use crate::bspc::{desktop::selector::DesktopSelector, selector::Assembleable};
2
3use super::direction::Direction;
4
5pub struct Path {
6 desktop_selector: Option<DesktopSelector>,
7 jumps: Vec<Jump>,
8 absolute: bool,
9}
10
11impl Path {
12 pub fn new() -> Path {
13 Path {
14 desktop_selector: None,
15 jumps: Vec::new(),
16 absolute: false,
17 }
18 }
19
20 pub fn set_desktop_selector(mut self, desktop_selector: DesktopSelector) -> Self {
21 self.desktop_selector = Some(desktop_selector);
22 return self;
23 }
24
25 pub fn set_absolute(mut self, absolute: bool) -> Self {
26 self.absolute = absolute;
27 return self;
28 }
29
30 pub fn add_jump(mut self, jump: Jump) -> Self {
31 self.jumps.push(jump);
32 return self;
33 }
34
35 pub(crate) fn assemble(&self) -> String {
36 let mut result = String::from("@");
37
38 match &self.desktop_selector {
39 Some(selector) => {
40 result.push_str(&selector.assemble(None));
41 result.push_str(":");
42 }
43 None => ()
44 }
45
46 for i in 0..self.jumps.len() {
47 let next_jump = &self.jumps[i];
48 if i == 0 && self.absolute || i != 0 {
49 result.push_str("/");
50 }
51 result.push_str(&format!("{}", next_jump.get_string()));
52 }
53 if self.jumps.len() == 0 && self.absolute {
54 result.push_str("/");
55 }
56 return result;
57 }
58}
59
60pub enum Jump {
61 First,
62 Second,
63 Brother,
64 Parent,
65 Dir(Direction),
67}
68
69impl Jump {
70 pub fn get_string(&self) -> String {
71 String::from(match self {
72 Jump::First => "first".to_string(),
73 Jump::Second => "second".to_string(),
74 Jump::Brother => "brother".to_string(),
75 Jump::Parent => "parent".to_string(),
76 Jump::Dir(dir) => dir.get_string(),
77 })
78 }
79}