feat: list views and binds

This commit is contained in:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 2026-01-17 01:37:50 +02:00
parent 204e26a324
commit a8f0fbb897
4 changed files with 68 additions and 9 deletions

View file

@ -32,6 +32,7 @@ uuid = { workspace = true, optional = true }
wavers = { workspace = true, optional = true }
winit = { workspace = true, optional = true }
xdg = { workspace = true }
ansi_term = "0.12.1"
[dev-dependencies]
proptest = { workspace = true }

View file

@ -36,7 +36,7 @@
},
tengri::tui::crossterm::{
self,
event::{Event, KeyCode::{self, *}},
event::{Event, KeyEvent, KeyCode::{self, *}},
},
};
@ -267,11 +267,11 @@ pub mod core {
&mut self, path: &str, defaults: &str, mut each: impl FnMut(&mut Self, &str)->Usually<()>
) -> Usually<()> {
if self.dirs.find_config_file(path).is_none() {
println!("Creating {path:?}");
//println!("Creating {path:?}");
std::fs::write(self.dirs.place_config_file(path)?, defaults)?;
}
Ok(if let Some(path) = self.dirs.find_config_file(path) {
println!("Loading {path:?}");
//println!("Loading {path:?}");
let src = std::fs::read_to_string(&path)?;
src.as_str().each(move|item|each(self, item))?;
} else {
@ -285,7 +285,7 @@ pub mod core {
let tail = expr.tail()?;
let name = tail.head()?;
let body = tail.tail()?;
println!("Config::load: {} {} {}", head.unwrap_or_default(), name.unwrap_or_default(), body.unwrap_or_default());
//println!("Config::load: {} {} {}", head.unwrap_or_default(), name.unwrap_or_default(), body.unwrap_or_default());
match head {
Some("mode") if let Some(name) = name =>
Mode::<Arc<str>>::load_into(&self.modes, &name, &body)?,
@ -305,14 +305,14 @@ pub mod core {
impl Mode<Arc<str>> {
pub fn load_into (modes: &Modes, name: &impl AsRef<str>, body: &impl Dsl) -> Usually<()> {
let mut mode = Self::default();
println!("Mode::load_into: {}: {body:?}", name.as_ref());
//println!("Mode::load_into: {}: {body:?}", name.as_ref());
body.each(|item|mode.load_one(item))?;
modes.write().unwrap().insert(name.as_ref().into(), Arc::new(mode));
Ok(())
}
fn load_one (&mut self, dsl: impl Dsl) -> Usually<()> {
Ok(if let Ok(Some(expr)) = dsl.expr() && let Ok(Some(head)) = expr.head() {
println!("Mode::load_one: {head} {:?}", expr.tail());
//println!("Mode::load_one: {head} {:?}", expr.tail());
let tail = expr.tail()?.map(|x|x.trim()).unwrap_or("");
match head {
"name" => self.name.push(tail.into()),
@ -369,7 +369,7 @@ pub mod core {
}
impl Bind<TuiEvent, Arc<str>> {
pub fn load_into (binds: &Binds, name: &impl AsRef<str>, body: &impl Dsl) -> Usually<()> {
println!("Bind::load_into: {}: {body:?}", name.as_ref());
//println!("Bind::load_into: {}: {body:?}", name.as_ref());
let mut map = Self::new();
body.each(|item|if item.expr().head() == Ok(Some("see")) {
// TODO
@ -942,7 +942,55 @@ pub mod glue {
let mut config = Config::new(None);
config.init()?;
if matches!(self.action, Action::Config) {
println!("{config:#?}");
use ::ansi_term::Color::*;
println!("{:?}", config.dirs);
for (k, v) in config.views.read().unwrap().iter() {
println!("{} {} {v}", Green.paint("VIEW"), Green.bold().paint(format!("{k:<16}")));
}
for (k, v) in config.binds.read().unwrap().iter() {
println!("{} {}", Green.paint("BIND"), Green.bold().paint(format!("{k:<16}")));
for (k, v) in v.0.iter() {
print!("{} ", &Yellow.paint(match &k.0 {
Event::Key(KeyEvent { modifiers, .. }) =>
format!("{:>16}", format!("{modifiers}")),
_ => unimplemented!()
}));
print!("{}", &Yellow.bold().paint(match &k.0 {
Event::Key(KeyEvent { code, .. }) =>
format!("{:<10}", format!("{code}")),
_ => unimplemented!()
}));
for v in v.iter() {
print!(" => {:?}", v.commands);
print!(" {}", v.condition.as_ref().map(|x|format!("{x:?}")).unwrap_or_default());
println!(" {}", v.description.as_ref().map(|x|x.as_ref()).unwrap_or_default());
//println!(" {:?}", v.source);
}
}
}
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}"))); }
println!();
for (k, v) in v.modes.read().unwrap().iter() {
print!("{} {} {:?}",
Green.paint(" MODE"),
Green.bold().paint(format!("{k:<16}")),
v.name);
print!(" INFO={:?}",
v.info);
print!(" VIEW={:?}",
v.view);
println!(" KEYS={:?}",
v.keys);
}
}
} else {
let name = self.name.as_ref().map_or("tek", |x|x.as_str());
let jack = Jack::new(&name)?;