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));
}
}