Generator

Trait Generator 

Source
pub trait Generator<'a> {
    type Convertor: TagConvertor<'a>;
    type Output;
    type Err: LocatedError + Display + Debug + Into<Error<'a, Self::Err>>;

    // Required methods
    fn convertor(&mut self) -> &mut Self::Convertor;
    fn generate(
        &mut self,
        ir: Vec<Vec<ItemG<'a, Self>>>,
    ) -> Result<Self::Output, Self::Err>;
}
Expand description

Generator generates final output to show tui markup in some backend.

§How to add support for new backend

Some concepts:

  • Markup text/Source: the text you write in tui markup language.
  • Parser: parse markup text into a series of Item, which usually be called as AST.
  • Tag Convertor: Convert raw tag string like green, bg:66ccff, mod:b into Tag.
  • Generator: generator final output from Item<Tag>.

So the whole pipeline is:

Source --- Parser --> Item --- Tag Convertor --> Item<Tag> --- Generator --> Output --> Show it in some backend

The source, parser, Item, Tag, is already defined, so just write a Tag Convertor and a Generator, a new backend will be supported.

§Generic implementation using flatten

Your tag convertor will parse color/modifiers string to some Color/Modifier type, and will support custom tag by a Style type, which can be converted from Color and Modifier too.

In this case, a Tag of this convertor can be convert to the Style type easily.

If this Style can be patched by other, then you can use the flatten help method to do almost all the convert staff from AST to your final result.

Read document of flatten to learn more, or just checkout a builtin implementation.

Required Associated Types§

Source

type Convertor: TagConvertor<'a>

Tag convertor type.

Source

type Output

Output type.

Source

type Err: LocatedError + Display + Debug + Into<Error<'a, Self::Err>>

Error type.

If the generator can’t fall, please use GeneratorInfallible.

Required Methods§

Source

fn convertor(&mut self) -> &mut Self::Convertor

Get the tag convertor.

Source

fn generate( &mut self, ir: Vec<Vec<ItemG<'a, Self>>>, ) -> Result<Self::Output, Self::Err>

Generates final output from IR, which is output result of the Convertor.

§Errors

When the generator can’t process the IR. This should be documented details.

Implementations on Foreign Types§

Source§

impl<'a, G: Generator<'a>> Generator<'a> for &mut G

Source§

type Convertor = <G as Generator<'a>>::Convertor

Source§

type Output = <G as Generator<'a>>::Output

Source§

type Err = <G as Generator<'a>>::Err

Source§

fn convertor(&mut self) -> &mut Self::Convertor

Source§

fn generate( &mut self, ir: Vec<Vec<ItemG<'a, G>>>, ) -> Result<Self::Output, Self::Err>

Implementors§

Source§

impl<'a, P> Generator<'a> for ANSIStringsGenerator<P>
where P: CustomTagParser<Output = Style>,

Available on crate feature ansi only.
Source§

impl<'a, P> Generator<'a> for CrosstermCommandsGenerator<P>
where P: CustomTagParser<Output = ContentStyle>,

Available on crate feature crossterm only.
Source§

impl<'a, P> Generator<'a> for RatatuiTextGenerator<P>
where P: CustomTagParser<Output = Style>,

Available on crate feature ratatui only.