display config better
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 2026-01-17 13:20:13 +02:00
parent 6ec445aab7
commit e0272a8a7d
2 changed files with 136 additions and 251 deletions

View file

@ -140,25 +140,21 @@ pub mod model {
},
});
}
pub mod core {
use super::{*, model::*, gui::*};
impl App {
/// Create a new application from a project, config, and mode
pub fn new (
jack: &Jack<'static>,
project: Arrangement,
config: Config,
mode: impl AsRef<str>
) -> Self {
Self {
color: ItemTheme::random(),
dialog: Dialog::welcome(),
jack: jack.clone(),
mode: config.modes.clone().read().unwrap().get(mode.as_ref()).cloned().unwrap(),
config,
project,
..Default::default()
}
let color = ItemTheme::random();
let dialog = Dialog::welcome();
let jack = jack.clone();
let mode = config.get_mode(mode).unwrap();
Self { color, dialog, jack, mode, config, project, ..Default::default() }
}
}
impl Config {
@ -166,10 +162,8 @@ pub mod core {
const DEFAULTS: &'static str = include_str!("./tek.edn");
/// Create a new app configuration from a set of XDG base directories,
pub fn new (dirs: Option<BaseDirectories>) -> Self {
Self {
dirs: dirs.unwrap_or_else(||BaseDirectories::with_profile("tek", "v0")),
..Default::default()
}
let dirs = dirs.unwrap_or_else(||BaseDirectories::with_profile("tek", "v0"));
Self { dirs, ..Default::default() }
}
/// Write initial contents of configuration.
pub fn init (&mut self) -> Usually<()> {
@ -214,6 +208,9 @@ pub mod core {
return Err(format!("Config::load: expected expr, got: {item:?}").into())
}
}
fn get_mode (&self, mode: impl AsRef<str>) -> Option<Arc<Mode<Arc<str>>>> {
self.modes.clone().read().unwrap().get(mode.as_ref()).cloned()
}
}
pub fn load_view (views: &Views, name: &impl AsRef<str>, body: &impl Dsl) -> Usually<()> {
views.write().unwrap().insert(name.as_ref().into(), body.src()?.unwrap_or_default().into());
@ -259,7 +256,6 @@ pub mod core {
match head {
"name" => self.name.push(tail.into()),
"info" => self.info.push(tail.into()),
"view" => self.view.push(tail.into()),
"keys" => tail.each(|expr|{
self.keys.push(expr.trim().into());
Ok(())
@ -269,9 +265,7 @@ pub mod core {
} else {
return Err(format!("Mode::add: self: incomplete: {expr:?}").into());
},
_ => {
return Err(format!("Mode::add: unexpected expr: {head:?} {tail:?}").into())
},
_ => self.view.push(tail.into())
};
} else if let Ok(Some(word)) = dsl.word() {
self.view.push(word.into());
@ -851,18 +845,18 @@ pub mod glue {
{ MaybeHas::<Track>::get_mut(&mut self.project) });
maybe_has!(Scene: |self: App| { MaybeHas::<Scene>::get(&self.project) };
{ MaybeHas::<Scene>::get_mut(&mut self.project) });
impl HasJack<'static> for App { fn jack (&self) -> &Jack<'static> { &self.jack } }
impl HasClipsSize for App { fn clips_size (&self) -> &Measure<TuiOut> { &self.project.size_inner } }
impl HasTrackScroll for App { fn track_scroll (&self) -> usize { self.project.track_scroll() } }
impl HasSceneScroll for App { fn scene_scroll (&self) -> usize { self.project.scene_scroll() } }
impl Default for AppCommand { fn default () -> Self { Self::Nop } }
impl ScenesView for App {
fn w_side (&self) -> u16 { 20 }
fn w_mid (&self) -> u16 { (self.width() as u16).saturating_sub(self.w_side()) }
fn h_scenes (&self) -> u16 { (self.height() as u16).saturating_sub(20) }
}
impl Default for MenuItem { fn default () -> Self { Self("".into(), Arc::new(Box::new(|_|Ok(())))) } }
impl Default for AppCommand { fn default () -> Self { Self::Nop } }
impl PartialEq for MenuItem { fn eq (&self, other: &Self) -> bool { self.0 == other.0 } }
impl HasJack<'static> for App { fn jack (&self) -> &Jack<'static> { &self.jack } }
impl HasClipsSize for App { fn clips_size (&self) -> &Measure<TuiOut> { &self.project.size_inner } }
impl HasTrackScroll for App { fn track_scroll (&self) -> usize { self.project.track_scroll() } }
impl HasSceneScroll for App { fn scene_scroll (&self) -> usize { self.project.scene_scroll() } }
impl AsRef<Arc<[MenuItem]>> for MenuItems { fn as_ref (&self) -> &Arc<[MenuItem]> { &self.0 } }
impl_debug!(MenuItem |self, w| { write!(w, "{}", &self.0) });
impl_debug!(Condition |self, w| { write!(w, "*") });
@ -875,15 +869,10 @@ pub mod glue {
use clap::{self, Parser, Subcommand};
/// CLI banner.
const HEADER: &'static str = r#"
~ ~~~~ ~ ~ ~~ ~ ~ ~ ~~ ~ ~ ~ ~ ~~~~~~ ~ ~~~
~~ ~ ~< ~ v0.3.0, 2025 sum(m)er @ the nose of the cat. ~
~~~ ~ ~ ~~~ ~ ~ ~ ~ ~~~ ~~~ ~ ~~ ~~ ~~ ~ ~~
On first run, Tek will create configuration and state dirs:
* [x] ~/.config/tek - config
* [ ] ~/.local/share/tek - projects
* [ ] ~/.local/lib/tek - plugins
* [ ] ~/.cache/tek - cache
~"#;
~ ~~~ ~ ~ ~~ ~ ~ ~ ~~ ~ ~ ~ ~
~ v0.4.0, 2026 winter (or is it) ~
~ ~ ~~~ ~ ~ ~ ~ ~~~ ~~~ ~ ~~ "#;
#[derive(Debug, Parser)]
#[command(name = "tek", version, about = Some(HEADER), long_about = Some(HEADER))]
pub struct Cli {
@ -1042,18 +1031,16 @@ pub mod glue {
}
}
for (k, v) in config.modes.read().unwrap().iter() {
println!("{} {} {:?} {:?}", Green.paint("\nTOOL "),
Green.bold().paint(format!("{k:<16}")),
v.name, v.info);
print!("{}", Green.paint(" VIEW"));
for v in v.view.iter() { print!(" {}", Yellow.paint(format!("{v}"))); }
println!();
print!("{}", Green.paint(" KEYS"));
for v in v.keys.iter() { print!(" {}", Yellow.paint(format!("{v}"))); }
for v in v.name.iter() { print!("{}", Green.bold().paint(format!("{v} "))); }
for v in v.info.iter() { print!("\n{}", Green.paint(format!("{v}"))); }
print!("\n{} {}", Blue.paint("TOOL"), Green.bold().paint(format!("{k:<16}")));
print!("\n{}", Blue.paint("KEYS"));
for v in v.keys.iter() { print!("{}", Green.paint(format!(" {v}"))); }
println!();
for (k, v) in v.modes.read().unwrap().iter() {
print!("{} {} {:?}",
Green.paint(" MODE"),
Blue.paint("MODE"),
Green.bold().paint(format!("{k:<16}")),
v.name);
print!(" INFO={:?}",
@ -1063,6 +1050,9 @@ pub mod glue {
println!(" KEYS={:?}",
v.keys);
}
print!("{}", Blue.paint("VIEW"));
for v in v.view.iter() { print!("{}", Green.paint(format!(" {v}"))); }
println!();
}
}
fn show_status (&self, project: &Arrangement) {