mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: load view/keys config from unified file
This commit is contained in:
parent
26baa8127d
commit
0efcb7f0fe
4 changed files with 50 additions and 14 deletions
|
|
@ -31,6 +31,7 @@ pub use ::tengri::tui::ratatui::prelude::Color::{self, *};
|
|||
pub use ::tengri::tui::ratatui::prelude::{Style, Stylize, Buffer, Modifier};
|
||||
pub use ::tengri::tui::crossterm;
|
||||
pub use ::tengri::tui::crossterm::event::{Event, KeyCode::{self, *}};
|
||||
pub(crate) use std::path::Path;
|
||||
pub(crate) use std::sync::{Arc, RwLock};
|
||||
pub(crate) use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering::Relaxed};
|
||||
|
||||
|
|
|
|||
|
|
@ -423,11 +423,51 @@ pub trait HasSelection {
|
|||
#[derive(Default, Debug)]
|
||||
pub struct Configuration {
|
||||
/// View definition
|
||||
pub view: SourceIter<'static>,
|
||||
pub view: TokenIter<'static>,
|
||||
// Input keymap
|
||||
pub keys: InputMap<'static, Tek, TekCommand, TuiIn, TokenIter<'static>>
|
||||
}
|
||||
|
||||
impl Configuration {
|
||||
pub fn from_file (path: &impl AsRef<Path>, _watch: bool) -> Usually<Self> {
|
||||
Self::from_source(String::from_utf8(std::fs::read(path.as_ref())?)?)
|
||||
}
|
||||
pub fn from_source (source: impl AsRef<str> + 'static) -> Usually<Self> {
|
||||
let source: Box<str> = source.as_ref().into();
|
||||
let source: &'static str = Box::leak(source);
|
||||
let iter = TokenIter::from(source.as_ref());
|
||||
let mut view: Option<TokenIter> = None;
|
||||
let mut keys: Option<TokenIter> = None;
|
||||
for token in iter {
|
||||
match token.value {
|
||||
Value::Exp(_, mut exp) => match exp.next() {
|
||||
Some(Token { value: Value::Sym(sym), .. }) => match sym {
|
||||
"keys" => keys = Some(exp),
|
||||
"view" => view = Some(exp),
|
||||
_ => return Err(format!("unexpected token {token:?}").into())
|
||||
},
|
||||
_ => return Err(format!("unexpected token {token:?}").into())
|
||||
},
|
||||
t => return Err(format!("unexpected token {token:?}").into())
|
||||
};
|
||||
}
|
||||
Ok(Self {
|
||||
view: if let Some(view) = view {
|
||||
view
|
||||
} else {
|
||||
return Err(format!("missing view definition").into())
|
||||
},
|
||||
keys: if let Some(keys) = keys {
|
||||
let mut map = InputMap::default();
|
||||
// TODO add layers
|
||||
map
|
||||
} else {
|
||||
return Err(format!("missing keys definition").into())
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Various possible modal overlays
|
||||
#[derive(PartialEq, Clone, Copy, Debug)]
|
||||
pub enum Modal {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue