Compare commits

...

2 commits

Author SHA1 Message Date
8bfd1a23a1 core, output: add Has, HasSize
Some checks are pending
/ build (push) Waiting to run
2025-05-14 17:53:34 +03:00
a9619ab9ce fix(proc): use TryFromDsl locally 2025-05-14 14:35:38 +03:00
4 changed files with 24 additions and 15 deletions

View file

@ -5,3 +5,17 @@ pub type Usually<T> = Result<T, Box<dyn Error>>;
/// Standard optional result type. /// Standard optional result type.
pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>; pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
/// Implement the `From` trait.
#[macro_export] macro_rules! from {
($(<$($lt:lifetime),+>)?|$state:ident:$Source:ty|$Target:ty=$cb:expr) => {
impl $(<$($lt),+>)? From<$Source> for $Target {
fn from ($state:$Source) -> Self { $cb }
}
};
}
pub trait Has<T>: Send + Sync {
fn get (&self) -> &T;
fn get_mut (&mut self) -> &mut T;
}

View file

@ -3,13 +3,17 @@ use std::sync::{Arc, atomic::{AtomicUsize, Ordering::Relaxed}};
pub trait HasSize<E: Output> { pub trait HasSize<E: Output> {
fn size (&self) -> &Measure<E>; fn size (&self) -> &Measure<E>;
fn width (&self) -> usize {
self.size().w()
}
fn height (&self) -> usize {
self.size().w()
}
} }
#[macro_export] macro_rules! has_size { impl<E: Output, T: Has<Measure<E>>> HasSize<E> for T {
(<$E:ty>|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => { fn size (&self) -> &Measure<E> {
impl $(<$($L),*$($T $(: $U)?),*>)? HasSize<$E> for $Struct $(<$($L),*$($T),*>)? { self.get()
fn size (&$self) -> &Measure<$E> { $cb }
}
} }
} }

View file

@ -82,6 +82,7 @@ impl ToTokens for CommandDef {
fn get <'source> (&self, iter: &mut ::tengri::dsl::TokenIter<'source>) fn get <'source> (&self, iter: &mut ::tengri::dsl::TokenIter<'source>)
-> Option<#enumeration> -> Option<#enumeration>
{ {
use ::tengri::dsl::TryFromDsl;
#enumeration::try_from_expr(self, iter) #enumeration::try_from_expr(self, iter)
} }
} }

View file

@ -33,16 +33,6 @@ pub use ::ratatui; pub(crate) use ratatui::{
pub(crate) use std::sync::{Arc, RwLock, atomic::{AtomicBool, Ordering::*}}; pub(crate) use std::sync::{Arc, RwLock, atomic::{AtomicBool, Ordering::*}};
pub(crate) use std::io::{stdout, Stdout}; pub(crate) use std::io::{stdout, Stdout};
pub(crate) use std::path::PathBuf;
pub(crate) use std::ffi::OsString;
#[macro_export] macro_rules! from {
($(<$($lt:lifetime),+>)?|$state:ident:$Source:ty|$Target:ty=$cb:expr) => {
impl $(<$($lt),+>)? From<$Source> for $Target {
fn from ($state:$Source) -> Self { $cb }
}
};
}
#[cfg(test)] #[test] fn test_tui_engine () -> Usually<()> { #[cfg(test)] #[test] fn test_tui_engine () -> Usually<()> {
use crate::*; use crate::*;