3 releases

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

#401 in Text processing

Download history 295/week @ 2024-09-11 53/week @ 2024-09-18 11/week @ 2024-09-25 5/week @ 2024-10-02 318/week @ 2024-10-09 153/week @ 2024-10-16 68/week @ 2024-10-23 75/week @ 2024-10-30 88/week @ 2024-11-06 55/week @ 2024-11-13 57/week @ 2024-11-20 46/week @ 2024-11-27 104/week @ 2024-12-04

276 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–13MB
~142K SLoC