57 lines
1.3 KiB
Rust
57 lines
1.3 KiB
Rust
use crate::types::HighlightRule;
|
|
|
|
pub struct HighlightManager {
|
|
pub rules: Vec<HighlightRule>,
|
|
pub show_editor: bool,
|
|
pub new_pattern: String,
|
|
pub new_color: [u8; 3],
|
|
}
|
|
|
|
impl HighlightManager {
|
|
pub fn new(rules: Vec<HighlightRule>) -> Self {
|
|
Self {
|
|
rules,
|
|
show_editor: false,
|
|
new_pattern: String::new(),
|
|
new_color: [255, 255, 0],
|
|
}
|
|
}
|
|
|
|
pub fn toggle_editor(&mut self) {
|
|
self.show_editor = !self.show_editor;
|
|
}
|
|
|
|
pub fn add_highlight(&mut self) -> bool {
|
|
if self.new_pattern.is_empty() {
|
|
return false;
|
|
}
|
|
|
|
self.rules.push(HighlightRule {
|
|
pattern: self.new_pattern.clone(),
|
|
color: self.new_color,
|
|
enabled: true,
|
|
});
|
|
|
|
self.new_pattern.clear();
|
|
true
|
|
}
|
|
|
|
pub fn remove_highlight(&mut self, index: usize) -> bool {
|
|
if index < self.rules.len() {
|
|
self.rules.remove(index);
|
|
true
|
|
} else {
|
|
false
|
|
}
|
|
}
|
|
|
|
pub fn toggle_rule(&mut self, index: usize) -> bool {
|
|
if let Some(rule) = self.rules.get_mut(index) {
|
|
rule.enabled = !rule.enabled;
|
|
true
|
|
} else {
|
|
false
|
|
}
|
|
}
|
|
}
|