mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-09-18 05:16:44 +02:00
move Keywords to dizzle
This commit is contained in:
parent
7f067b848f
commit
7c9816a07e
2 changed files with 1 additions and 82 deletions
2
dizzle
2
dizzle
|
|
@ -1 +1 @@
|
||||||
Subproject commit 0cd70c4d1ac7299cef32ee0d6a02a632e62d6af3
|
Subproject commit b6c1bb5f9400c28de1709df78c18e0d4d5618a15
|
||||||
81
src/lib.rs
81
src/lib.rs
|
|
@ -1898,86 +1898,5 @@ pub trait AsMutOpt<T> { fn as_mut_opt (&mut self) -> Option<&mut T>; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "eval")] pub use self::eval::*;
|
|
||||||
#[cfg(feature = "eval")] mod eval {
|
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
/// ```
|
|
||||||
/// # use ::tengri::{*, dizzle::*, ratatui::prelude::Color};
|
|
||||||
///
|
|
||||||
/// #[namespace(bool)]
|
|
||||||
/// #[namespace(u8)]
|
|
||||||
/// #[namespace(u16)]
|
|
||||||
/// #[namespace(Option<u16>)]
|
|
||||||
/// #[namespace(Color get_color)]
|
|
||||||
/// struct App;
|
|
||||||
///
|
|
||||||
/// fn get_color (state: &App, src: impl Language) -> Perhaps<Color> {
|
|
||||||
/// Ok(if let Some(color) = Tui::eval_color_expr(state, &src)? {
|
|
||||||
/// Some(color)
|
|
||||||
/// } else if let Some(sym) = src.word()? {
|
|
||||||
/// Some(match sym {
|
|
||||||
/// ":color/bg" => Color::Rgb(28, 32, 36),
|
|
||||||
/// ":color/fg" => Color::Rgb(98, 92, 96),
|
|
||||||
/// _ => return Err(format!("not a color: {sym}").into())
|
|
||||||
/// })
|
|
||||||
/// } else {
|
|
||||||
/// return Err(format!("not a color: {:?}", src.src()?).into())
|
|
||||||
/// })
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// impl Interpret<Tui, Option<XYWH<u16>>> for App {
|
|
||||||
/// fn interpret_expr <'a> (&'a self, to: &mut Tui, lang: &'a impl Language)
|
|
||||||
/// -> Usually<Option<XYWH<u16>>>
|
|
||||||
/// {
|
|
||||||
/// self.keyword(to, lang)
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// impl Keywords<Tui, XYWH<u16>> for App {
|
|
||||||
/// fn keywords () -> impl Iterator<Item = fn(&Self, &mut Tui, &str) -> Perhaps<XYWH<u16>>> {
|
|
||||||
/// [
|
|
||||||
/// kw_when, kw_either, kw_split, kw_align,
|
|
||||||
/// kw_exact, kw_min, kw_max, kw_push,
|
|
||||||
/// kw_tui_text, kw_tui_fg, kw_tui_bg
|
|
||||||
/// ].into_iter()
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// # fn main () -> tengri::Usually<()> {
|
|
||||||
/// let state = App;
|
|
||||||
/// let mut out = Tui::new(80, 25);
|
|
||||||
/// state.interpret_expr(&mut out, &"")?;
|
|
||||||
/// state.interpret_expr(&mut out, &"text Hello world!")?;
|
|
||||||
/// state.interpret_expr(&mut out, &"fg (g 0) (text Hello world!)")?;
|
|
||||||
/// state.interpret_expr(&mut out, &"bg (g 2) (text Hello world!)")?;
|
|
||||||
/// state.interpret_expr(&mut out, &"(bg (g 3) (fg (g 4) (text Hello world!)))")?;
|
|
||||||
/// # Ok(()) }
|
|
||||||
/// ```
|
|
||||||
pub trait Keywords <U, V>: 'static {
|
|
||||||
fn keywords <'a> () -> impl Iterator<Item = fn(&Self, &mut U, &str) -> PerhapsRef<'a, V>>;
|
|
||||||
fn keyword <'a> (&self, to: &mut U, expr: &'a (impl Language + ?Sized)) -> PerhapsRef<'a, V> {
|
|
||||||
if let Some(expr) = expr.src()? {
|
|
||||||
for keyword in Self::keywords() {
|
|
||||||
if let Some(result) = keyword(self, to, &expr)? {
|
|
||||||
return Ok(Some(result))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export] macro_rules! impl_keywords {
|
|
||||||
($T:ty, $U:ty, $V:ty [ $($kw:ident),* ]) => {
|
|
||||||
impl Keywords<$T, $U> for $V {
|
|
||||||
fn keywords <'a> () -> impl Iterator<Item = fn(&Self, &mut $T, &str) -> PerhapsRef<'a, $U>> {
|
|
||||||
[ $($kw),* ].into_iter()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "term")] pub use self::term::*;
|
#[cfg(feature = "term")] pub use self::term::*;
|
||||||
#[cfg(feature = "term")] mod term;
|
#[cfg(feature = "term")] mod term;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue