orchestrator
This commit is contained in:
83
src/orchestrator/mode.rs
Normal file
83
src/orchestrator/mode.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
// path_from_the_root: src/orchestrator/mode.rs
|
||||
|
||||
use alloc::collections::BTreeMap;
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum ModeName {
|
||||
General,
|
||||
Navigation,
|
||||
Editing,
|
||||
Command,
|
||||
Custom(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ModeStack {
|
||||
modes: Vec<ModeName>,
|
||||
}
|
||||
|
||||
impl ModeStack {
|
||||
pub fn new() -> Self {
|
||||
Self { modes: Vec::new() }
|
||||
}
|
||||
|
||||
pub fn push(&mut self, mode: ModeName) {
|
||||
self.modes.push(mode);
|
||||
}
|
||||
|
||||
pub fn pop(&mut self) -> Option<ModeName> {
|
||||
self.modes.pop()
|
||||
}
|
||||
|
||||
pub fn current(&self) -> Option<&ModeName> {
|
||||
self.modes.last()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.modes.is_empty()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.modes.len()
|
||||
}
|
||||
|
||||
pub fn contains(&self, mode: &ModeName) -> bool {
|
||||
self.modes.contains(mode)
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.modes.clear();
|
||||
}
|
||||
|
||||
pub fn reset(&mut self, mode: ModeName) {
|
||||
self.modes.clear();
|
||||
self.modes.push(mode);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ModeResolver {
|
||||
mappings: BTreeMap<String, Vec<ModeName>>,
|
||||
}
|
||||
|
||||
impl ModeResolver {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
mappings: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register(&mut self, key: String, modes: Vec<ModeName>) {
|
||||
self.mappings.insert(key, modes);
|
||||
}
|
||||
|
||||
pub fn resolve(&self, key: &str) -> Option<&Vec<ModeName>> {
|
||||
self.mappings.get(key)
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.mappings.is_empty()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user