3 releases

0.1.2 Oct 12, 2024
0.1.1 Sep 15, 2024
0.1.0 Sep 15, 2024

#377 in Text processing

Download history 214/week @ 2024-09-09 129/week @ 2024-09-16 9/week @ 2024-09-23 12/week @ 2024-09-30 243/week @ 2024-10-07 185/week @ 2024-10-14 100/week @ 2024-10-21 64/week @ 2024-10-28 89/week @ 2024-11-04 56/week @ 2024-11-11

325 downloads per month
Used in tailspin

MIT license

105KB
2K SLoC

manifold is the highlighting crate powering tailspin.

Getting started

Run the following Cargo command in your project directory:

cargo add inlet_manifold

Create highlighter from default

The quickest way to get starting with manifold is using the default constructor. It will provide you with a highlighter with most of the highlighters enabled and sensible ordering and defaults.

Note that colors, ordering and highlight groups might change between versions. To ensure a more deterministic behavior, use the builder pattern.

let highlighter = Highlighter::default();

let input = "Hello 42 world".to_string();
let output = highlighter.apply(input);

println!("{}", input);  // "Hello 42 world"
println!("{}", output); // "Hello \u{1b}[36m42\u{1b}[0m world!"

Create highlighter with builder pattern

Use the builder pattern to specify both styling and ordering of the highlighters. The order in which each highlighter is added is significant. manifold will apply the highlighters in the order they were added.

Once an item is highlighted, it will not be overwritten by a subsequent highlighter.

let mut builder = Highlighter::builder();

builder
    .with_number_highlighter(NumberConfig {
        number: Style {
            fg: Some(Color::Cyan),
            ..Style::default()
        },
    })
    .with_quote_highlighter(QuoteConfig {
        quotes_token: '"',
        color: Style {
            fg: Some(Color::Yellow),
            ..Style::default()
        },
    })
    .with_uuid_highlighter(UuidConfig::default());
   

// Using the highlight builder can fail if the regexes inside don't compile
let highlighter = match builder.build {
    Ok(h) => h,
    Err(_) => panic!("Failed to build highlighter"),
};

let input = "Hello 42 world".to_string();
let output = highlighter.apply(input);

println!("{}", input);  // "Hello 42 world"
println!("{}", output); // "Hello \u{1b}[36m42\u{1b}[0m world!"

Dependencies

~4–12MB
~138K SLoC