mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-01-31 08:36:40 +01:00
feat: list views and binds
This commit is contained in:
parent
204e26a324
commit
a8f0fbb897
4 changed files with 68 additions and 9 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -79,6 +79,15 @@ version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"
|
checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ansi_term"
|
||||||
|
version = "0.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstream"
|
name = "anstream"
|
||||||
version = "0.6.20"
|
version = "0.6.20"
|
||||||
|
|
@ -2383,6 +2392,7 @@ dependencies = [
|
||||||
name = "tek"
|
name = "tek"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"ansi_term",
|
||||||
"atomic_float",
|
"atomic_float",
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ uuid = { workspace = true, optional = true }
|
||||||
wavers = { workspace = true, optional = true }
|
wavers = { workspace = true, optional = true }
|
||||||
winit = { workspace = true, optional = true }
|
winit = { workspace = true, optional = true }
|
||||||
xdg = { workspace = true }
|
xdg = { workspace = true }
|
||||||
|
ansi_term = "0.12.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
proptest = { workspace = true }
|
proptest = { workspace = true }
|
||||||
|
|
|
||||||
64
app/tek.rs
64
app/tek.rs
|
|
@ -36,7 +36,7 @@
|
||||||
},
|
},
|
||||||
tengri::tui::crossterm::{
|
tengri::tui::crossterm::{
|
||||||
self,
|
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<()>
|
&mut self, path: &str, defaults: &str, mut each: impl FnMut(&mut Self, &str)->Usually<()>
|
||||||
) -> Usually<()> {
|
) -> Usually<()> {
|
||||||
if self.dirs.find_config_file(path).is_none() {
|
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)?;
|
std::fs::write(self.dirs.place_config_file(path)?, defaults)?;
|
||||||
}
|
}
|
||||||
Ok(if let Some(path) = self.dirs.find_config_file(path) {
|
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)?;
|
let src = std::fs::read_to_string(&path)?;
|
||||||
src.as_str().each(move|item|each(self, item))?;
|
src.as_str().each(move|item|each(self, item))?;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -285,7 +285,7 @@ pub mod core {
|
||||||
let tail = expr.tail()?;
|
let tail = expr.tail()?;
|
||||||
let name = tail.head()?;
|
let name = tail.head()?;
|
||||||
let body = tail.tail()?;
|
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 {
|
match head {
|
||||||
Some("mode") if let Some(name) = name =>
|
Some("mode") if let Some(name) = name =>
|
||||||
Mode::<Arc<str>>::load_into(&self.modes, &name, &body)?,
|
Mode::<Arc<str>>::load_into(&self.modes, &name, &body)?,
|
||||||
|
|
@ -305,14 +305,14 @@ pub mod core {
|
||||||
impl Mode<Arc<str>> {
|
impl Mode<Arc<str>> {
|
||||||
pub fn load_into (modes: &Modes, name: &impl AsRef<str>, body: &impl Dsl) -> Usually<()> {
|
pub fn load_into (modes: &Modes, name: &impl AsRef<str>, body: &impl Dsl) -> Usually<()> {
|
||||||
let mut mode = Self::default();
|
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))?;
|
body.each(|item|mode.load_one(item))?;
|
||||||
modes.write().unwrap().insert(name.as_ref().into(), Arc::new(mode));
|
modes.write().unwrap().insert(name.as_ref().into(), Arc::new(mode));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn load_one (&mut self, dsl: impl Dsl) -> Usually<()> {
|
fn load_one (&mut self, dsl: impl Dsl) -> Usually<()> {
|
||||||
Ok(if let Ok(Some(expr)) = dsl.expr() && let Ok(Some(head)) = expr.head() {
|
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("");
|
let tail = expr.tail()?.map(|x|x.trim()).unwrap_or("");
|
||||||
match head {
|
match head {
|
||||||
"name" => self.name.push(tail.into()),
|
"name" => self.name.push(tail.into()),
|
||||||
|
|
@ -369,7 +369,7 @@ pub mod core {
|
||||||
}
|
}
|
||||||
impl Bind<TuiEvent, Arc<str>> {
|
impl Bind<TuiEvent, Arc<str>> {
|
||||||
pub fn load_into (binds: &Binds, name: &impl AsRef<str>, body: &impl Dsl) -> Usually<()> {
|
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();
|
let mut map = Self::new();
|
||||||
body.each(|item|if item.expr().head() == Ok(Some("see")) {
|
body.each(|item|if item.expr().head() == Ok(Some("see")) {
|
||||||
// TODO
|
// TODO
|
||||||
|
|
@ -942,7 +942,55 @@ pub mod glue {
|
||||||
let mut config = Config::new(None);
|
let mut config = Config::new(None);
|
||||||
config.init()?;
|
config.init()?;
|
||||||
if matches!(self.action, Action::Config) {
|
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 {
|
} else {
|
||||||
let name = self.name.as_ref().map_or("tek", |x|x.as_str());
|
let name = self.name.as_ref().map_or("tek", |x|x.as_str());
|
||||||
let jack = Jack::new(&name)?;
|
let jack = Jack::new(&name)?;
|
||||||
|
|
|
||||||
2
deps/tengri
vendored
2
deps/tengri
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8c54510f630e8a81b7d7bdca0a51a69cdb9dffcc
|
Subproject commit b0d2fad17beef84be8f1fdad116643563379a2c1
|
||||||
Loading…
Add table
Add a link
Reference in a new issue