From a9619ab9cea40aed3ec30483f4a7db03ca7fec9d Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 14 May 2025 14:35:38 +0300 Subject: [PATCH 1/2] fix(proc): use TryFromDsl locally --- core/src/lib.rs | 9 +++++++++ proc/src/proc_command.rs | 1 + tui/src/lib.rs | 10 ---------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 22288d1..18c672b 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -5,3 +5,12 @@ pub type Usually = Result>; /// Standard optional result type. pub type Perhaps = Result, Box>; + +/// 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 } + } + }; +} diff --git a/proc/src/proc_command.rs b/proc/src/proc_command.rs index bfe9246..f8e9d2a 100644 --- a/proc/src/proc_command.rs +++ b/proc/src/proc_command.rs @@ -82,6 +82,7 @@ impl ToTokens for CommandDef { fn get <'source> (&self, iter: &mut ::tengri::dsl::TokenIter<'source>) -> Option<#enumeration> { + use ::tengri::dsl::TryFromDsl; #enumeration::try_from_expr(self, iter) } } diff --git a/tui/src/lib.rs b/tui/src/lib.rs index 01eb7d9..79648b9 100644 --- a/tui/src/lib.rs +++ b/tui/src/lib.rs @@ -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::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<()> { use crate::*; From 8bfd1a23a1f880a1d2fb104a158fc51f244acd6e Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 14 May 2025 17:53:34 +0300 Subject: [PATCH 2/2] core, output: add Has, HasSize --- core/src/lib.rs | 5 +++++ output/src/space/measure.rs | 14 +++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 18c672b..f3cf313 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -14,3 +14,8 @@ pub type Perhaps = Result, Box>; } }; } + +pub trait Has: Send + Sync { + fn get (&self) -> &T; + fn get_mut (&mut self) -> &mut T; +} diff --git a/output/src/space/measure.rs b/output/src/space/measure.rs index 2a1e415..9ea4765 100644 --- a/output/src/space/measure.rs +++ b/output/src/space/measure.rs @@ -3,13 +3,17 @@ use std::sync::{Arc, atomic::{AtomicUsize, Ordering::Relaxed}}; pub trait HasSize { fn size (&self) -> &Measure; + fn width (&self) -> usize { + self.size().w() + } + fn height (&self) -> usize { + self.size().w() + } } -#[macro_export] macro_rules! has_size { - (<$E:ty>|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => { - impl $(<$($L),*$($T $(: $U)?),*>)? HasSize<$E> for $Struct $(<$($L),*$($T),*>)? { - fn size (&$self) -> &Measure<$E> { $cb } - } +impl>> HasSize for T { + fn size (&self) -> &Measure { + self.get() } }