tui-pattern-highlighter

Crates.iotui-pattern-highlighter
lib.rstui-pattern-highlighter
version0.2.2
sourcesrc
created_at2024-05-27 16:43:21.325302
updated_at2024-08-10 21:01:49.213106
descriptiona dead simple search pattern highlighter for ratatui
homepage
repositoryhttps://github.com/0watcher/tui-pattern-highlighter
max_upload_size
id1253562
size8,715
Patryk Strużek (0b-s3rv3r)

documentation

README

tui-pattern-highlighter

Version Tests Docs

a dead simple search pattern highlighter for ratatui

Example

use tui_pattern_highlighter::highlight_line;
use ratatui::{
    style::{Color, Style},
    text::{Line, Span, Text},
};

let line = "Hi @buddy";
let pattern = r"@\w+";
let highlight_style = Style::new().bg(Color::Blue);

let expected_line = Line::from(vec![
    Span::from("Hi "),
    Span::from("@buddy").style(Style::new().bg(Color::Blue)),
]);

assert_eq!(highlight_line(line, pattern, highlight_style), expected_line);

let text = "Hi @buddy\n@stranger hello";
let pattern = r"@\w+";
let highlight_style = Style::new().bg(Color::Blue);

let expected_text = Text::from(vec![
    Line::from(vec![
        Span::from("Hi "),
        Span::from("@buddy").style(Style::new().bg(Color::Blue)),
    ]),
    Line::from(vec![
        Span::from("@stranger").style(Style::new().bg(Color::Blue)),
        Span::from(" hello"),
    ]),
]);

assert_eq!(highlight_text(text, pattern, highlight_style), expected_text);
Commit count: 8

cargo fmt