tui: keybinds work?
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
🪞👃🪞 2025-08-10 01:14:26 +03:00
parent b52c1f5828
commit 24ac52d807
10 changed files with 238 additions and 203 deletions

View file

@ -7,25 +7,26 @@ pub(crate) struct ViewDef(pub(crate) ViewMeta, pub(crate) ViewImpl);
pub(crate) struct ViewMeta { pub(crate) output: Ident }
#[derive(Debug, Clone)]
pub(crate) struct ViewImpl {
block: ItemImpl,
exposed: BTreeMap<String, Ident>,
}
pub(crate) struct ViewImpl { block: ItemImpl, exposed: BTreeMap<String, Ident>, }
/// `#[view]` takes 1 arg ([Engine] implementation for which it's valid).
impl Parse for ViewMeta {
fn parse (input: ParseStream) -> Result<Self> {
Ok(Self {
output: input.parse::<Ident>()?,
})
Ok(Self { output: input.parse::<Ident>()?, })
}
}
/// `#[view]` exposes each function as corresponding symbol.
///
/// Maybe it's best to genericize that pattern rather than have
/// 3 whole things for the layers of the program.
impl Parse for ViewImpl {
fn parse (input: ParseStream) -> Result<Self> {
let block = input.parse::<ItemImpl>()?;
let mut exposed: BTreeMap<String, Ident> = Default::default();
for item in block.items.iter() {
if let ImplItem::Fn(ImplItemFn { sig: Signature { ident, .. }, .. }) = item {
if let ImplItem::Fn(ImplItemFn { sig: Signature { ident, inputs, .. }, .. }) = item
&& inputs.len() == 1 {
let key = format!(":{}", AsKebabCase(format!("{}", &ident)));
if exposed.contains_key(&key) {
return Err(input.error(format!("already defined: {ident}")));
@ -37,6 +38,7 @@ impl Parse for ViewImpl {
}
}
/// `#[view]`'s output is a generated block of symbol bindings.
impl ToTokens for ViewDef {
fn to_tokens (&self, out: &mut TokenStream2) {
let Self(_, ViewImpl { block, .. }) = self;
@ -78,10 +80,8 @@ impl ViewDef {
/// Makes [#self_ty] able to construct the [Render]able
/// which might correspond to a given [TokenStream],
/// while taking [#self_ty]'s state into consideration.
impl<'state> ::tengri::dsl::DslInto<'state,
Box<dyn ::tengri::output::Render<#output> + 'state>
> for #self_ty {
fn dsl_into (&'state self, dsl: &impl ::tengri::dsl::Dsl)
impl<'state> ::tengri::dsl::DslInto<Box<dyn ::tengri::output::Render<#output> + 'state>> for #self_ty {
fn dsl_into (&self, dsl: &impl ::tengri::dsl::Dsl)
-> Perhaps<Box<dyn ::tengri::output::Render<#output> + 'state>>
{
#(#builtins)*