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
143
src/conf/mode.rs
143
src/conf/mode.rs
|
|
@ -2,6 +2,95 @@ use crate::*;
|
|||
|
||||
impl_as_mut!(Mode: |self: Mode| self);
|
||||
|
||||
/// Has a stack of currently active interaction modes.
|
||||
pub trait HasModeStack {
|
||||
/// Stack of active modes.
|
||||
fn mode_stack (&self) -> &RwLock<Vec<Arc<str>>>;
|
||||
}
|
||||
|
||||
impl HasModeStack for App {
|
||||
fn mode_stack (&self) -> &RwLock<Vec<Arc<str>>> {
|
||||
&self.modes
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HasModes {
|
||||
fn modes (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<Mode>>>;
|
||||
|
||||
/// Register a mode.
|
||||
///
|
||||
/// ```
|
||||
/// # use ::{std::sync::Arc, tek::*};
|
||||
/// let config: Config = Default::default();
|
||||
///
|
||||
/// config.modes_add(stringify!(Menu
|
||||
/// (name Menu)
|
||||
/// (info Mode selector.)
|
||||
/// (axis Y Prev Next)
|
||||
/// (bind Confirm)
|
||||
/// (view (bg (g 30) (bar/s 7 Logo (full/xy Dialog))))
|
||||
/// )).unwrap();
|
||||
///
|
||||
/// let _: Arc<Mode> = config.modes_get("Menu").unwrap();
|
||||
/// ```
|
||||
fn modes_add <'a> (&self, expr: impl Language) -> UsuallyRef<'a, ()> {
|
||||
let name = expr.head()?.ok_or("mode: missing name")?;
|
||||
let body = expr.tail()?.ok_or("mode: missing body")?;
|
||||
let mut mode = Mode::default();
|
||||
body.each(&mut mode, |c, s|c.add(s))?;
|
||||
self.modes().write().insert(name.into(), Arc::new(mode));
|
||||
Ok(())
|
||||
}
|
||||
/// Get a mode by name.
|
||||
fn modes_get (&self, name: impl AsRef<str>) -> Option<Arc<Mode>> {
|
||||
self.modes().read().get(name.as_ref()).cloned()
|
||||
}
|
||||
/// Run something for each mode.
|
||||
fn modes_for_each <T> (&self, mut ator: impl FnMut(&str, &Mode)->T) {
|
||||
for (k, v) in self.modes().read().iter() {
|
||||
let _ = ator(k.as_ref(), v.as_ref());
|
||||
}
|
||||
}
|
||||
/// Count modes.
|
||||
fn modes_count (&self) -> usize {
|
||||
self.modes().read().len()
|
||||
}
|
||||
/// Clear modes.
|
||||
fn modes_clear (&self) {
|
||||
*self.modes().write() = Default::default();
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModes for App {
|
||||
fn modes (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<Mode>>> {
|
||||
&self.config.config.modes.0
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModes for ConfigWatcher {
|
||||
fn modes (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<Mode>>> {
|
||||
&self.config.modes.0
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModes for Config {
|
||||
fn modes (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<Mode>>> {
|
||||
&self.modes.0
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModes for Modes {
|
||||
fn modes (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<Mode>>> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModes for Mode {
|
||||
fn modes (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<Mode>>> {
|
||||
&self.modes.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Collection of UI modes.
|
||||
///
|
||||
/// ```
|
||||
|
|
@ -114,38 +203,24 @@ impl Mode {
|
|||
|
||||
}
|
||||
|
||||
impl ControlAxis {
|
||||
pub fn eval <'a> (_: &App, src: impl Language) -> Perhaps<ControlAxis> {
|
||||
eval_word(src, |word|Ok(ControlAxis(word.into())))
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModes for App {
|
||||
fn modes (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<Mode>>> {
|
||||
&self.config.config.modes.0
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModes for ConfigWatcher {
|
||||
fn modes (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<Mode>>> {
|
||||
&self.config.modes.0
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModes for Config {
|
||||
fn modes (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<Mode>>> {
|
||||
&self.modes.0
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModes for Modes {
|
||||
fn modes (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<Mode>>> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModes for Mode {
|
||||
fn modes (&self) -> &RwLock<BTreeMap<Arc<str>, Arc<Mode>>> {
|
||||
&self.modes.0
|
||||
}
|
||||
pub fn print_config_modes (config: &Config) {
|
||||
use ::ansi_term::Color::*;
|
||||
config.modes_for_each(|k, v|{
|
||||
println!();
|
||||
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!();
|
||||
v.modes_for_each(|k, v|{
|
||||
print!("{} {} {:?}", Blue.paint("MODE"), Green.bold().paint(format!("{k:<16}")), v.name);
|
||||
print!( " INFO={:?}", v.info);
|
||||
print!( " VIEW={:?}", v.view);
|
||||
println!(" KEYS={:?}", v.keys);
|
||||
});
|
||||
print!("{}", Blue.paint("VIEW"));
|
||||
for v in v.view.iter() { print!("{}", Green.paint(format!(" {v}"))); }
|
||||
println!();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue