mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
wip: configuring keybinds with edn... oh my
This commit is contained in:
parent
f1bd9e7e88
commit
1f10c95ed0
6 changed files with 73 additions and 35 deletions
|
|
@ -21,6 +21,8 @@ mod tui_field; pub use self::tui_field::*;
|
|||
mod tui_buffer; pub use self::tui_buffer::*;
|
||||
mod tui_file; pub use self::tui_file::*;
|
||||
|
||||
mod tui_edn_keymap; pub use self::tui_edn_keymap::*;
|
||||
|
||||
pub(crate) use std::sync::{Arc, RwLock, atomic::{AtomicUsize, AtomicBool, Ordering::*}};
|
||||
pub(crate) use std::io::{stdout, Stdout};
|
||||
pub(crate) use std::error::Error;
|
||||
|
|
|
|||
26
tui/src/tui_edn_keymap.rs
Normal file
26
tui/src/tui_edn_keymap.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use crate::*;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub trait EdnControlData<E: Input> {}
|
||||
|
||||
/// Renders from EDN source and context.
|
||||
#[derive(Default)]
|
||||
pub enum EdnControls<E: Input, T: EdnControlData<E>> {
|
||||
#[default]
|
||||
Inert,
|
||||
_Unused(PhantomData<E>),
|
||||
Ok(T, EdnItem<String>),
|
||||
Err(String)
|
||||
}
|
||||
|
||||
impl<E: Input, T: EdnControlData<E>> EdnControls<E, T> {
|
||||
pub fn from_source (state: T, source: &str) -> Self {
|
||||
match EdnItem::read_one(&source) {
|
||||
Ok((layout, _)) => Self::Ok(state, layout),
|
||||
Err(error) => Self::Err(format!("{error}"))
|
||||
}
|
||||
}
|
||||
pub fn from_items (state: T, items: &[EdnItem<&str>]) -> Self {
|
||||
Self::Ok(state, EdnItem::Exp(items.iter().map(|i|(*i).clone()).collect()))
|
||||
}
|
||||
}
|
||||
|
|
@ -68,15 +68,3 @@ impl TuiOut {
|
|||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn buffer_update (buf: &mut Buffer, area: [u16;4], callback: &impl Fn(&mut Cell, u16, u16)) {
|
||||
for row in 0..area.h() {
|
||||
let y = area.y() + row;
|
||||
for col in 0..area.w() {
|
||||
let x = area.x() + col;
|
||||
if x < buf.area.width && y < buf.area.height {
|
||||
callback(buf.get_mut(x, y), col, row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue