mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 03:36:41 +01:00
parent
e9f912f4d9
commit
f488811767
3 changed files with 39 additions and 22 deletions
|
|
@ -1,16 +1,16 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use xdg::BaseDirectories;
|
use xdg::BaseDirectories;
|
||||||
/// Configurations
|
/// Configuration
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct Configurations {
|
pub struct Configurations {
|
||||||
pub dirs: BaseDirectories,
|
pub dirs: BaseDirectories,
|
||||||
pub current: Option<Configuration>,
|
pub current: Option<Profile>,
|
||||||
pub profiles: Arc<RwLock<std::collections::BTreeMap<Arc<str>, Arc<str>>>>,
|
pub profiles: Arc<RwLock<std::collections::BTreeMap<Arc<str>, Profile>>>,
|
||||||
pub bindings: Arc<RwLock<std::collections::BTreeMap<Arc<str>, Arc<str>>>>,
|
pub bindings: Arc<RwLock<std::collections::BTreeMap<Arc<str>, Arc<str>>>>,
|
||||||
}
|
}
|
||||||
/// Configuration
|
/// Profile
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct Configuration {
|
pub struct Profile {
|
||||||
/// Path of configuration entrypoint
|
/// Path of configuration entrypoint
|
||||||
pub path: std::path::PathBuf,
|
pub path: std::path::PathBuf,
|
||||||
/// Name of configuration
|
/// Name of configuration
|
||||||
|
|
@ -22,6 +22,21 @@ pub struct Configuration {
|
||||||
// Input keymap
|
// Input keymap
|
||||||
pub keys: EventMap<TuiEvent, AppCommand>,
|
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 {
|
impl Configurations {
|
||||||
const PROFILES: &'static str = "profiles.edn";
|
const PROFILES: &'static str = "profiles.edn";
|
||||||
const BINDINGS: &'static str = "bindings.edn";
|
const BINDINGS: &'static str = "bindings.edn";
|
||||||
|
|
@ -32,15 +47,14 @@ impl Configurations {
|
||||||
let mut cfgs = Self { dirs, ..Default::default() };
|
let mut cfgs = Self { dirs, ..Default::default() };
|
||||||
cfgs.init_file(Self::PROFILES, Self::DEFAULT_PROFILES)?;
|
cfgs.init_file(Self::PROFILES, Self::DEFAULT_PROFILES)?;
|
||||||
cfgs.load_file(Self::PROFILES, |cfgs, dsl|{
|
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 exp = dsl.exp()?;
|
||||||
let tail = exp.tail()?;
|
let tail = exp.tail()?;
|
||||||
let head = tail.head()?;
|
let head = tail.head()?;
|
||||||
if let Some(name) = tail.head()?.sym()? {
|
if let Some(id) = head.sym()? {
|
||||||
let body = tail.tail()?;
|
|
||||||
cfgs.profiles.write().unwrap().insert(
|
cfgs.profiles.write().unwrap().insert(
|
||||||
name.into(),
|
id.into(),
|
||||||
body.unwrap_or_default().into()
|
Profile::from_dsl(tail.tail()?)?
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -81,7 +95,7 @@ impl Configurations {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Configuration {
|
impl Profile {
|
||||||
fn load_template (&mut self, dsl: impl Dsl) -> Usually<&mut Self> {
|
fn load_template (&mut self, dsl: impl Dsl) -> Usually<&mut Self> {
|
||||||
dsl.src()?.unwrap_or_default().each(|item|Ok(match () {
|
dsl.src()?.unwrap_or_default().each(|item|Ok(match () {
|
||||||
_ if let Some(exp) = dsl.exp()? => match exp.head()?.key()? {
|
_ if let Some(exp) = dsl.exp()? => match exp.head()?.key()? {
|
||||||
|
|
|
||||||
|
|
@ -38,16 +38,19 @@ impl App {
|
||||||
"nil"
|
"nil"
|
||||||
}
|
}
|
||||||
pub fn view_menu (&self) -> impl Content<TuiOut> + use<'_> {
|
pub fn view_menu (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
Stack::south(|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
|
Bsp::s(Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), Tui::bold(true, "tek 0.3.0-rc0")))),
|
||||||
add(&Tui::bold(true, "tek 0.3.0-rc0"));
|
Bsp::n(Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), "+ new session"))),
|
||||||
add(&"");
|
Fill::xy(Stack::south(|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
|
||||||
for (name, _) in self.configs.profiles.read().unwrap().iter() {
|
for (index, (id, profile)) in self.configs.profiles.read().unwrap().iter().enumerate() {
|
||||||
add(&"");
|
add(&Fixed::y(3, Tui::bg(if index == 0 { Rgb(64,64,64) } else { Rgb(32,32,32) }, Bsp::s(
|
||||||
add(&name);
|
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))
|
||||||
|
))));
|
||||||
}
|
}
|
||||||
add(&"");
|
}))))
|
||||||
add(&"+ new session");
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
pub fn view_dialog (&self) -> impl Content<TuiOut> + use<'_> {
|
pub fn view_dialog (&self) -> impl Content<TuiOut> + use<'_> {
|
||||||
self.dialog.as_ref().map(|dialog|Bsp::b("",
|
self.dialog.as_ref().map(|dialog|Bsp::b("",
|
||||||
|
|
|
||||||
2
deps/tengri
vendored
2
deps/tengri
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9ccd7e5c69f6f8aa5ab43f22d5953d56427d4f14
|
Subproject commit 104bb1c8e76cacf249ccd340712ea7bd2d33b5f6
|
||||||
Loading…
Add table
Add a link
Reference in a new issue