wip: load view/keys config from unified file

This commit is contained in:
🪞👃🪞 2025-05-02 19:58:03 +03:00
parent 26baa8127d
commit 0efcb7f0fe
4 changed files with 50 additions and 14 deletions

View file

@ -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::ratatui::prelude::{Style, Stylize, Buffer, Modifier};
pub use ::tengri::tui::crossterm; pub use ::tengri::tui::crossterm;
pub use ::tengri::tui::crossterm::event::{Event, KeyCode::{self, *}}; 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::{Arc, RwLock};
pub(crate) use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering::Relaxed}; pub(crate) use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering::Relaxed};

View file

@ -423,11 +423,51 @@ pub trait HasSelection {
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub struct Configuration { pub struct Configuration {
/// View definition /// View definition
pub view: SourceIter<'static>, pub view: TokenIter<'static>,
// Input keymap // Input keymap
pub keys: InputMap<'static, Tek, TekCommand, TuiIn, TokenIter<'static>> 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 /// Various possible modal overlays
#[derive(PartialEq, Clone, Copy, Debug)] #[derive(PartialEq, Clone, Copy, Debug)]
pub enum Modal { pub enum Modal {

View file

@ -139,19 +139,14 @@ impl Cli {
}, },
scenes, scenes,
selected: Selection::TrackClip { track: 0, scene: 0 }, selected: Selection::TrackClip { track: 0, scene: 0 },
config: Configuration::from(match mode { config: Configuration::from_file(match mode {
LaunchMode::Clock => LaunchMode::Clock => &"config/config_transport.edn",
include_str!("../../config/view_transport.edn"), LaunchMode::Sequencer => &"config/config_sequencer.edn",
LaunchMode::Sequencer => LaunchMode::Groovebox => &"config/config_groovebox.edn",
include_str!("../../config/view_sequencer.edn"), LaunchMode::Arranger { .. } => &"config/config_arranger.edn",
LaunchMode::Groovebox => LaunchMode::Sampler => &"config/config_sampler.edn",
include_str!("../../config/view_groovebox.edn"),
LaunchMode::Arranger { .. } =>
include_str!("../../config/view_arranger.edn"),
LaunchMode::Sampler =>
include_str!("../../config/view_sampler.edn"),
_ => todo!("{mode:?}"), _ => todo!("{mode:?}"),
}), }, false)?,
..Default::default() ..Default::default()
}; };
if let &LaunchMode::Arranger { scenes, tracks, track_width, .. } = mode { if let &LaunchMode::Arranger { scenes, tracks, track_width, .. } = mode {

2
deps/tengri vendored

@ -1 +1 @@
Subproject commit 2b208e3c497d595f7dad5a6d190dfe08f7fb9dc0 Subproject commit 0d4ba4a54ef0528a0a45b58e21a1e4aa7ed5eaf9