mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-01-31 10:56:41 +01:00
output: refactor Content and Render traits
This commit is contained in:
parent
74b3af2212
commit
1c21a85f27
24 changed files with 346 additions and 613 deletions
|
|
@ -5,7 +5,7 @@ macro_rules! impl_content_layout_render {
|
|||
layout = $layout:expr;
|
||||
render = $render:expr) =>
|
||||
{
|
||||
impl Content<$Output> for $Struct {
|
||||
impl Render<$Output> for $Struct {
|
||||
fn layout (&$self, $to: [u16;4]) -> [u16;4] { $layout }
|
||||
fn render (&$self, $to: &mut $Output) { $render }
|
||||
}
|
||||
|
|
@ -25,19 +25,19 @@ mod tui_string; pub use self::tui_string::*;
|
|||
mod tui_style; pub use self::tui_style::*;
|
||||
mod tui_tryptich; pub use self::tui_tryptich::*;
|
||||
|
||||
impl<T: Content<TuiOut>> Content<TuiOut> for std::sync::Arc<T> {
|
||||
impl<T: Render<TuiOut>> Render<TuiOut> for std::sync::Arc<T> {
|
||||
fn layout (&self, to: [u16;4]) -> [u16;4] {
|
||||
Content::<TuiOut>::layout(&**self, to)
|
||||
Render::<TuiOut>::layout(&**self, to)
|
||||
}
|
||||
fn render (&self, to: &mut TuiOut) {
|
||||
Content::<TuiOut>::render(&**self, to)
|
||||
Render::<TuiOut>::render(&**self, to)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Content<TuiOut>> Content<TuiOut> for Result<T, Box<dyn std::error::Error>> {
|
||||
fn content (&self) -> impl Render<TuiOut> {
|
||||
Bsp::a(self.as_ref().ok(), self.as_ref().err()
|
||||
.map(|e|Tui::fg_bg(Color::Rgb(255,255,255), Color::Rgb(32,32,32), e.to_string())))
|
||||
impl<T: Render<TuiOut>> Content<TuiOut> for Result<T, Box<dyn std::error::Error>> {
|
||||
fn content (&self) -> Option<impl Render<TuiOut> + '_> {
|
||||
Some(Bsp::a(self.as_ref().ok(), self.as_ref().err()
|
||||
.map(|e|Tui::fg_bg(Color::Rgb(255,255,255), Color::Rgb(32,32,32), e.to_string()))))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue