mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-10-08 18:56:42 +02:00
flatten conf
This commit is contained in:
parent
b050e0e014
commit
56df5c5b78
9 changed files with 1840 additions and 1868 deletions
|
|
@ -1691,12 +1691,33 @@ impl ClockView {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait HasViews {
|
||||
fn views (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<View<Tui, App>>>>;
|
||||
/// Load custom view definition.
|
||||
fn views_add <'a> (&self, expr: impl Language) -> UsuallyRef<'a, ()> {
|
||||
self.views().write().insert(
|
||||
expr.head()?.ok_or("view: missing name")?.into(),
|
||||
View::new(expr.tail()?.ok_or("view: missing body")?)?.into()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
fn views_clear (&self) {
|
||||
*self.views().write() = Default::default();
|
||||
}
|
||||
fn views_get (&self, name: impl AsRef<str>) -> Option<Arc<View<Tui, App>>> {
|
||||
self.views().read().get(name.as_ref()).cloned()
|
||||
}
|
||||
fn views_for_each <T> (&self, cb: impl Fn(&Arc<str>, &Arc<View<Tui, App>>)->T) -> () {
|
||||
for (k, v) in self.views().read().iter() {
|
||||
cb(k, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
impl HasViews for App {
|
||||
fn views (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<View<Tui, App>>>> {
|
||||
&self.config.config.views.0
|
||||
}
|
||||
}
|
||||
|
||||
impl HasViews for Config {
|
||||
fn views (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<View<Tui, App>>>> {
|
||||
&self.views.0
|
||||
|
|
@ -1722,3 +1743,10 @@ impl HasViews for Config {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_config_views (config: &Config) {
|
||||
use ::ansi_term::Color::*;
|
||||
config.views_for_each(|k, v|{
|
||||
println!("{} {} {}", Green.paint("VIEW"), Green.bold().paint(format!("{k:<16}")), v.source);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue