mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-07 04:06:48 +01:00
Compare commits
No commits in common. "7c348c3b1d1f864821f0524905942e55ad8bdeda" and "21f7f6b38afc966b7b45af442935d48c8c5067d3" have entirely different histories.
7c348c3b1d
...
21f7f6b38a
9 changed files with 5 additions and 175 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
|
@ -972,15 +972,6 @@ dependencies = [
|
||||||
"tengri_tui",
|
"tengri_tui",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tengri_proc"
|
|
||||||
version = "0.13.0"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tengri_tui"
|
name = "tengri_tui"
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.13.0"
|
version = "0.13.0"
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
@ -9,8 +8,7 @@ members = [
|
||||||
"./input",
|
"./input",
|
||||||
"./output",
|
"./output",
|
||||||
"./tui",
|
"./tui",
|
||||||
"./dsl",
|
"./dsl"
|
||||||
"./proc",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tengri_dsl"
|
name = "tengri_dsl"
|
||||||
|
edition = "2024"
|
||||||
description = "UI metaframework, tiny S-expression-based DSL."
|
description = "UI metaframework, tiny S-expression-based DSL."
|
||||||
version = { workspace = true }
|
version = { workspace = true }
|
||||||
edition = { workspace = true }
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
konst = { version = "0.3.16", features = [ "rust_1_83" ] }
|
konst = { version = "0.3.16", features = [ "rust_1_83" ] }
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tengri_input"
|
name = "tengri_input"
|
||||||
|
edition = "2024"
|
||||||
description = "UI metaframework, input layer."
|
description = "UI metaframework, input layer."
|
||||||
version = { workspace = true }
|
version = { workspace = true }
|
||||||
edition = { workspace = true }
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tengri_dsl = { optional = true, path = "../dsl" }
|
tengri_dsl = { optional = true, path = "../dsl" }
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tengri_output"
|
name = "tengri_output"
|
||||||
|
edition = "2024"
|
||||||
description = "UI metaframework, output layer."
|
description = "UI metaframework, output layer."
|
||||||
version = { workspace = true }
|
version = { workspace = true }
|
||||||
edition = { workspace = true }
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tengri_dsl = { optional = true, path = "../dsl" }
|
tengri_dsl = { optional = true, path = "../dsl" }
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "tengri_proc"
|
|
||||||
description = "UI metaframework, procedural macros."
|
|
||||||
version = { workspace = true }
|
|
||||||
edition = { workspace = true }
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
proc-macro = true
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
syn = { version = "2", features = ["full"] }
|
|
||||||
quote = { version = "1" }
|
|
||||||
proc-macro2 = { version = "1", features = ["span-locations"] }
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
extern crate proc_macro;
|
|
||||||
use proc_macro::TokenStream;
|
|
||||||
use proc_macro2::{TokenStream as TokenStream2};
|
|
||||||
|
|
||||||
mod proc_view;
|
|
||||||
|
|
||||||
#[proc_macro_attribute]
|
|
||||||
pub fn view (meta: TokenStream, item: TokenStream) -> TokenStream {
|
|
||||||
self::proc_view::view_impl(meta.into(), item.into()).into()
|
|
||||||
//for attr in syn::parse_macro_input!(meta as syn::MetaList).iter() {
|
|
||||||
//}
|
|
||||||
//let item = syn::parse_macro_input!(item as syn::ItemImpl);
|
|
||||||
//let output = "TuiOut";
|
|
||||||
//let target = "Tek";
|
|
||||||
//let define = "self.config.view";
|
|
||||||
//let expose = vec![];
|
|
||||||
//let output = format!(
|
|
||||||
//"::tengri_dsl::view!({}:|self:{}|self.size.of(::tengri_dsl::View(self,{}));{{{}}});",
|
|
||||||
//output,
|
|
||||||
//target,
|
|
||||||
//define,
|
|
||||||
//expose.iter().fold(String::new(), |acc, (key, value)|format!("{acc},{key}=>{value}")),
|
|
||||||
//);
|
|
||||||
//let output = "";
|
|
||||||
//output.parse().unwrap()
|
|
||||||
}
|
|
||||||
|
|
@ -1,120 +0,0 @@
|
||||||
use proc_macro::TokenStream;
|
|
||||||
use proc_macro2::{TokenStream as TokenStream2, TokenTree, Ident};
|
|
||||||
use syn::parse_macro_input;
|
|
||||||
use syn::{Expr, Attribute, Meta, MetaList, Path, PathSegment, PathArguments, ImplItem};
|
|
||||||
use syn::parse::{Parse, ParseStream, Result};
|
|
||||||
use syn::token::PathSep;
|
|
||||||
use syn::punctuated::Punctuated;
|
|
||||||
|
|
||||||
pub(crate) fn view_impl (meta: TokenStream, item: TokenStream) -> TokenStream {
|
|
||||||
let ViewMeta { output, define, attrs, .. } = parse_macro_input!(meta as ViewMeta);
|
|
||||||
let ViewItem { target, mapped, items, .. } = parse_macro_input!(item as ViewItem);
|
|
||||||
quote::quote! {
|
|
||||||
#(#attrs)*
|
|
||||||
impl #target {
|
|
||||||
#(#items)*
|
|
||||||
}
|
|
||||||
/// Generated by [tengri_proc].
|
|
||||||
impl ::tengri::Content<#output> for #target {
|
|
||||||
fn content (&self) -> impl Render<#output> {
|
|
||||||
self.size.of(::tengri::View(self, #define))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// Generated by [tengri_proc].
|
|
||||||
impl<'a> ::tengri::ViewContext<'a, #output> for #target {
|
|
||||||
fn get_content_sym (&'a self, value: &Value<'a>) -> Option<RenderBox<'a, #output>> {
|
|
||||||
match value {
|
|
||||||
#mapped
|
|
||||||
_ => panic!("expected Sym(content), got: {value:?}")
|
|
||||||
}
|
|
||||||
//if let Value::Sym(s) = value {
|
|
||||||
//match *s {
|
|
||||||
//$($sym => Some($body.boxed()),)*
|
|
||||||
//_ => None
|
|
||||||
//}
|
|
||||||
//} else {
|
|
||||||
//panic!("expected Sym(content), got: {value:?}")
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ViewMeta {
|
|
||||||
attrs: Vec<Attribute>,
|
|
||||||
output: Option<Ident>,
|
|
||||||
define: Expr,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parse for ViewMeta {
|
|
||||||
fn parse (input: ParseStream) -> Result<Self> {
|
|
||||||
let mut output = None;
|
|
||||||
let mut define = None;
|
|
||||||
let mut attrs = input.call(Attribute::parse_outer)?.into_iter().filter(|attr| {
|
|
||||||
if let Attribute { meta: Meta::List(MetaList { path, tokens, .. }), .. } = attr
|
|
||||||
&& path.segments.len() == 2
|
|
||||||
&& nth_segment_is(&path.segments, 0, "tengri")
|
|
||||||
&& nth_segment_is(&path.segments, 1, "view")
|
|
||||||
&& let Some(TokenTree::Group(group)) = tokens.clone().into_iter().next()
|
|
||||||
&& let Some(TokenTree::Ident(ident)) = group.stream().into_iter().next()
|
|
||||||
{
|
|
||||||
output = Some(ident);
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}).collect();
|
|
||||||
|
|
||||||
if let Some(define) = define {
|
|
||||||
Ok(Self { attrs, output, define })
|
|
||||||
} else {
|
|
||||||
Err(input.error("Missing view definition."))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn nth_segment_is (segments: &Punctuated<PathSegment, PathSep>, n: usize, x: &str) -> bool {
|
|
||||||
if let Some(PathSegment { arguments: PathArguments::None, ident, .. }) = segments.get(n) {
|
|
||||||
if format!("{ident}") != x {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ViewItem {
|
|
||||||
items: Vec<ImplItem>,
|
|
||||||
target: &'static str,
|
|
||||||
mapped: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Parse for ViewItem {
|
|
||||||
fn parse (input: ParseStream) -> Result<Self> {
|
|
||||||
let items = vec![];
|
|
||||||
Ok(Self {
|
|
||||||
items,
|
|
||||||
target: "",
|
|
||||||
mapped: "",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)] #[test] fn test_view () {
|
|
||||||
|
|
||||||
use syn::{ItemImpl, parse_quote};
|
|
||||||
|
|
||||||
let _: ItemImpl = parse_quote! {
|
|
||||||
#[tengri::view(Tui)]
|
|
||||||
impl SomeView {
|
|
||||||
#[tengri::view]
|
|
||||||
fn view (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
"view-1"
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tengri::view(":view-1")]
|
|
||||||
fn view_1 (&self) -> impl Content<TuiOut> + use<'_> {
|
|
||||||
"view-1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tengri_tui"
|
name = "tengri_tui"
|
||||||
|
edition = "2024"
|
||||||
description = "UI metaframework, Ratatui backend."
|
description = "UI metaframework, Ratatui backend."
|
||||||
version = { workspace = true }
|
version = { workspace = true }
|
||||||
edition = { workspace = true }
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
palette = { version = "0.7.6", features = [ "random" ] }
|
palette = { version = "0.7.6", features = [ "random" ] }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue