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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use crossterm::event::KeyEvent;
use tty_interface::Style;
use crate::{
dependency::{Action, DependencyId, Evaluation},
step::CompoundStep,
text::{DrawerContents, Segment, Text},
};
use super::Control;
pub struct StaticText {
text: String,
style: Option<Style>,
dependency: Option<(DependencyId, Action)>,
}
impl StaticText {
pub fn new(text: &str) -> Self {
Self {
text: text.to_string(),
style: None,
dependency: None,
}
}
pub fn set_text(&mut self, text: &str) {
self.text = text.to_string();
}
pub fn set_style(&mut self, style: Style) {
self.style = Some(style);
}
pub fn set_dependency(&mut self, id: DependencyId, action: Action) {
self.dependency = Some((id, action));
}
}
impl Control for StaticText {
fn focusable(&self) -> bool {
false
}
fn update(&mut self, _input: KeyEvent) {}
fn help(&self) -> Option<Segment> {
None
}
fn text(&self) -> (Segment, Option<u16>) {
(Text::new(self.text.to_string()).as_segment(), None)
}
fn drawer(&self) -> Option<DrawerContents> {
None
}
fn evaluation(&self) -> Option<(DependencyId, Evaluation)> {
None
}
fn dependency(&self) -> Option<(DependencyId, Action)> {
self.dependency.clone()
}
fn evaluate(&self, _evaluation: &Evaluation) -> bool {
false
}
fn add_to(self, step: &mut CompoundStep) {
step.add_control(Box::new(self));
}
}