show main menu
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
🪞👃🪞 2025-08-03 21:23:08 +03:00
parent e9f912f4d9
commit f488811767
3 changed files with 39 additions and 22 deletions

View file

@ -1,16 +1,16 @@
use crate::*;
use xdg::BaseDirectories;
/// Configurations
/// Configuration
#[derive(Default, Debug)]
pub struct Configurations {
pub dirs: BaseDirectories,
pub current: Option<Configuration>,
pub profiles: Arc<RwLock<std::collections::BTreeMap<Arc<str>, Arc<str>>>>,
pub current: Option<Profile>,
pub profiles: Arc<RwLock<std::collections::BTreeMap<Arc<str>, Profile>>>,
pub bindings: Arc<RwLock<std::collections::BTreeMap<Arc<str>, Arc<str>>>>,
}
/// 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<TuiEvent, AppCommand>,
}
impl Profile {
fn from_dsl (dsl: impl Dsl) -> Usually<Self> {
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()? {

View file

@ -38,16 +38,19 @@ impl App {
"nil"
}
pub fn view_menu (&self) -> impl Content<TuiOut> + use<'_> {
Stack::south(|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
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<TuiOut>)|{
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<TuiOut> + use<'_> {
self.dialog.as_ref().map(|dialog|Bsp::b("",