init, basic glogg clone
This commit is contained in:
56
src/highlight.rs
Normal file
56
src/highlight.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user