tui markup

crates.io changelog docs.rs deps state

This crate provides a markup language to quickly write colorful and styled terminal text in plain text.

Usage

```rust use ansiterm::{ANSIStrings, Color, Style}; use tuimarkup::{compile, compile_with, generator::ANSIStringsGenerator};

// Parse markup into some final result for showing let result = compile::("You got a ").unwrap(); // Show it println!("{}", ANSIStrings(&result));

// With custom tag let gen = ANSIStringsGenerator::new(|tag: &str| match tag { "keyboard" => Some(Style::default().fg(Color::Blue).on(Color::Black).bold()), _ => None, }); let result = compile_with("Press to jump", gen).unwrap(); println!("{}", ANSIStrings(&result)); ```

Result:

result of example

Notice the result type and how to show it is vary depends on what Generator you use.

Current available built-in generators:

There is also a macro([tui-markup-ansi-macro] crate) to compile markup source into ANSI sequence at compile time, check it if you need.

You can add this markup support for other terminal/library/application easily by create you own generator.

Examples

help text

The example is shown in Windows Terminal, using the following command:

cargo run --example tui --features tui -- examples/help.txt

The source markup text of this article can be found in [examples/help.txt].

you can change the last argument to your file to render other article, for example examples/indexed.txt for a full xterm256 color chart:

color chart

Those two screenshot are using built-in tui generator.

Markup syntax

Only one syntax <taglist content> to add style to content.

taglist is a tag list sep by ,.

tag has format of mode:value, available mode are:

Mode and : is optional except for bg:, so 66ccff = fg:66ccf , and b = mod:b.

Some examples:

And you can define your own tag, like example code above.

The formal syntax spec can be found in [docs/syntax.ebnf].

Color and modifier supports vary by generator you want to use, see their document for details.

TODO

LICENSE

BSD-3-Clause-Clear, See [LICENSE].