diff --git a/crates/app/src/config.rs b/crates/app/src/config.rs index f0f5011a..6fa417c6 100644 --- a/crates/app/src/config.rs +++ b/crates/app/src/config.rs @@ -1,16 +1,16 @@ use crate::*; use xdg::BaseDirectories; -/// Configurations +/// Configuration #[derive(Default, Debug)] pub struct Configurations { pub dirs: BaseDirectories, - pub current: Option, - pub profiles: Arc, Arc>>>, + pub current: Option, + pub profiles: Arc, Profile>>>, pub bindings: Arc, Arc>>>, } -/// Configuration +/// Profile #[derive(Default, Debug)] -pub struct Configuration { +pub struct Profile { /// Path of configuration entrypoint pub path: std::path::PathBuf, /// Name of configuration @@ -22,6 +22,21 @@ pub struct Configuration { // Input keymap pub keys: EventMap, } +impl Profile { + fn from_dsl (dsl: impl Dsl) -> Usually { + let mut profile = Self { ..Default::default() }; + dsl.each(|dsl|{ + let head = dsl.head(); + let exp = dsl.exp(); + Ok(if exp.head().key() == Ok(Some("name")) { + profile.name = Some(exp.tail()?.unwrap_or_default().into()); + } else if exp.head().key() == Ok(Some("info")) { + profile.info = Some(exp.tail()?.unwrap_or_default().into()); + }) + })?; + Ok(profile) + } +} impl Configurations { const PROFILES: &'static str = "profiles.edn"; const BINDINGS: &'static str = "bindings.edn"; @@ -32,15 +47,14 @@ impl Configurations { let mut cfgs = Self { dirs, ..Default::default() }; cfgs.init_file(Self::PROFILES, Self::DEFAULT_PROFILES)?; cfgs.load_file(Self::PROFILES, |cfgs, dsl|{ - Ok(if dsl.exp().head()?.key()? == Some("module") { + Ok(if dsl.exp().head().key() == Ok(Some("module")) { let exp = dsl.exp()?; let tail = exp.tail()?; let head = tail.head()?; - if let Some(name) = tail.head()?.sym()? { - let body = tail.tail()?; + if let Some(id) = head.sym()? { cfgs.profiles.write().unwrap().insert( - name.into(), - body.unwrap_or_default().into() + id.into(), + Profile::from_dsl(tail.tail()?)? ); } } else { @@ -81,7 +95,7 @@ impl Configurations { }) } } -impl Configuration { +impl Profile { fn load_template (&mut self, dsl: impl Dsl) -> Usually<&mut Self> { dsl.src()?.unwrap_or_default().each(|item|Ok(match () { _ if let Some(exp) = dsl.exp()? => match exp.head()?.key()? { diff --git a/crates/app/src/view.rs b/crates/app/src/view.rs index a556fd86..23a1f0ab 100644 --- a/crates/app/src/view.rs +++ b/crates/app/src/view.rs @@ -38,16 +38,19 @@ impl App { "nil" } pub fn view_menu (&self) -> impl Content + use<'_> { - Stack::south(|add: &mut dyn FnMut(&dyn Render)|{ - add(&Tui::bold(true, "tek 0.3.0-rc0")); - add(&""); - for (name, _) in self.configs.profiles.read().unwrap().iter() { - add(&""); - add(&name); - } - add(&""); - add(&"+ new session"); - }) + Bsp::s(Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), Tui::bold(true, "tek 0.3.0-rc0")))), + Bsp::n(Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), "+ new session"))), + Fill::xy(Stack::south(|add: &mut dyn FnMut(&dyn Render)|{ + for (index, (id, profile)) in self.configs.profiles.read().unwrap().iter().enumerate() { + add(&Fixed::y(3, Tui::bg(if index == 0 { Rgb(64,64,64) } else { Rgb(32,32,32) }, Bsp::s( + Fill::x(Bsp::a( + Fill::x(Align::w(Tui::fg(Rgb(224,192,128), &profile.name))), + Fill::x(Align::e(Tui::fg(Rgb(224,128,32), id))) + )), + Fill::x(Align::w(&profile.info)) + )))); + } + })))) } pub fn view_dialog (&self) -> impl Content + use<'_> { self.dialog.as_ref().map(|dialog|Bsp::b("", diff --git a/deps/tengri b/deps/tengri index 9ccd7e5c..104bb1c8 160000 --- a/deps/tengri +++ b/deps/tengri @@ -1 +1 @@ -Subproject commit 9ccd7e5c69f6f8aa5ab43f22d5953d56427d4f14 +Subproject commit 104bb1c8e76cacf249ccd340712ea7bd2d33b5f6