1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub enum Status {
    Success,
    Failure,
    #[default]
    Running,
    // Initialized,
}

#[derive(Clone, Debug)]
pub struct TreeRepr {
    pub name: &'static str,
    pub status: Status,
    pub detail: String,
    pub children: Vec<TreeRepr>,
}

impl TreeRepr {
    pub fn new(name: &'static str, children: Vec<TreeRepr>) -> Self {
        Self {
            name,
            status: Status::Running,
            detail: "".to_owned(),
            children,
        }
    }

    pub fn with_detail(self, detail: String) -> Self {
        Self { detail, ..self }
    }

    pub fn with_status(self, status: Status) -> Self {
        Self { status, ..self }
    }
}

#[derive(Debug, Default)]
pub enum Cursor {
    // Condition(bool),
    Index(usize, Box<DebugRepr>),
    #[default]
    Leaf,
}

impl Cursor {
    pub fn index(&self) -> usize {
        match self {
            Cursor::Index(i, _) => *i,
            Cursor::Leaf => unreachable!(),
        }
    }
}

#[derive(Debug, Default)]
pub struct DebugRepr {
    pub name: String,
    pub params: Option<String>,
    pub status: Status,

    pub cursor: Cursor,
}

impl DebugRepr {
    pub fn new(name: &str, cursor: Cursor, status: Status) -> Self {
        Self {
            name: name.to_string(),
            cursor,
            status,
            params: None,
        }
    }
}