mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
Compare commits
2 commits
bad20f5037
...
8bfd1a23a1
| Author | SHA1 | Date | |
|---|---|---|---|
| 8bfd1a23a1 | |||
| a9619ab9ce |
4 changed files with 24 additions and 15 deletions
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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::*;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue