output: more big refactors

This commit is contained in:
🪞👃🪞 2025-09-07 12:34:30 +03:00
parent 194f2f9874
commit 5e6338fad8
68 changed files with 1604 additions and 1016 deletions

View file

@ -1,70 +1 @@
use crate::*;
pub trait TuiStyle {
fn fg <R: Render<TuiOut>> (color: Color, w: R) -> Foreground<R> {
Foreground(color, w)
}
fn bg <R: Render<TuiOut>> (color: Color, w: R) -> Background<R> {
Background(color, w)
}
fn fg_bg <R: Render<TuiOut>> (fg: Color, bg: Color, w: R) -> Background<Foreground<R>> {
Background(bg, Foreground(fg, w))
}
fn modify <R: Render<TuiOut>> (enable: bool, modifier: Modifier, w: R) -> Modify<R> {
Modify(enable, modifier, w)
}
fn bold <R: Render<TuiOut>> (enable: bool, w: R) -> Modify<R> {
Self::modify(enable, Modifier::BOLD, w)
}
fn border <R: Render<TuiOut>, S: BorderStyle> (enable: bool, style: S, w: R) -> Bordered<S, R> {
Bordered(enable, style, w)
}
}
impl TuiStyle for Tui {}
pub struct Foreground<R>(pub Color, pub R);
impl<R: Render<TuiOut>> Render<TuiOut> for Foreground<R> {
fn layout (&self, to: [u16;4]) -> [u16;4] {
self.1.layout(to)
}
fn render (&self, to: &mut TuiOut) {
let area = self.layout(to.area());
to.fill_fg(area, self.0);
to.place(area, &self.1);
}
}
pub struct Background<R>(pub Color, pub R);
impl<R: Render<TuiOut>> Render<TuiOut> for Background<R> {
fn layout (&self, to: [u16;4]) -> [u16;4] {
self.1.layout(to)
}
fn render (&self, to: &mut TuiOut) {
let area = self.layout(to.area());
to.fill_bg(area, self.0);
to.place(area, &self.1);
}
}
pub struct Modify<R: Render<TuiOut>>(pub bool, pub Modifier, pub R);
impl<R: Render<TuiOut>> Render<TuiOut> for Modify<R> {
fn layout (&self, to: [u16;4]) -> [u16;4] {
self.2.layout(to)
}
fn render (&self, to: &mut TuiOut) {
to.fill_mod(to.area(), self.0, self.1);
self.2.render(to)
}
}
pub struct Styled<R: Render<TuiOut>>(pub Option<Style>, pub R);
impl<R: Render<TuiOut>> Render<TuiOut> for Styled<R> {
fn layout (&self, to: [u16;4]) -> [u16;4] {
self.1.layout(to)
}
fn render (&self, to: &mut TuiOut) {
to.place(self.1.layout(to.area()), &self.1);
// TODO write style over area
}
}