mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
config: load view (and maybe name/info?)
This commit is contained in:
parent
0efcb7f0fe
commit
aefc147347
3 changed files with 72 additions and 49 deletions
|
|
@ -419,55 +419,6 @@ pub trait HasSelection {
|
|||
fn selected_mut (&mut self) -> &mut Selection;
|
||||
}
|
||||
|
||||
/// Configuration
|
||||
#[derive(Default, Debug)]
|
||||
pub struct Configuration {
|
||||
/// View definition
|
||||
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