tty_form/control/
statictext.rs1use crossterm::event::KeyEvent;
2use tty_interface::Style;
3
4use crate::{
5 dependency::{Action, DependencyId, Evaluation},
6 step::CompoundStep,
7 text::{DrawerContents, Segment, Text},
8};
9
10use super::Control;
11
12pub struct StaticText {
30 text: String,
31 style: Option<Style>,
32 dependency: Option<(DependencyId, Action)>,
33}
34
35impl StaticText {
36 pub fn new(text: &str) -> Self {
38 Self {
39 text: text.to_string(),
40 style: None,
41 dependency: None,
42 }
43 }
44
45 pub fn set_text(&mut self, text: &str) {
47 self.text = text.to_string();
48 }
49
50 pub fn set_style(&mut self, style: Style) {
52 self.style = Some(style);
53 }
54
55 pub fn set_dependency(&mut self, id: DependencyId, action: Action) {
57 self.dependency = Some((id, action));
58 }
59}
60
61impl Control for StaticText {
62 fn focusable(&self) -> bool {
63 false
64 }
65
66 fn update(&mut self, _input: KeyEvent) {}
67
68 fn help(&self) -> Option<Segment> {
69 None
70 }
71
72 fn text(&self) -> (Segment, Option<u16>) {
73 (Text::new(self.text.to_string()).as_segment(), None)
74 }
75
76 fn drawer(&self) -> Option<DrawerContents> {
77 None
78 }
79
80 fn evaluation(&self) -> Option<(DependencyId, Evaluation)> {
81 None
82 }
83
84 fn dependency(&self) -> Option<(DependencyId, Action)> {
85 self.dependency.clone()
86 }
87
88 fn evaluate(&self, _evaluation: &Evaluation) -> bool {
89 false
90 }
91
92 fn add_to(self, step: &mut CompoundStep) {
93 step.add_control(Box::new(self));
94 }
95}