#pattern #highlighter #ratatui #dead #search-pattern #tui #line

tui-pattern-highlighter

a dead simple search pattern highlighter for ratatui

4 releases

0.2.2 Aug 10, 2024
0.2.1 Jul 17, 2024
0.2.0 May 30, 2024
0.1.0 May 27, 2024

#1000 in Command-line interface

Download history 7/week @ 2024-07-22 97/week @ 2024-08-05 25/week @ 2024-08-12 14/week @ 2024-09-16 5/week @ 2024-09-23 29/week @ 2024-09-30

284 downloads per month

MIT license

8KB
88 lines

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);

Dependencies

~8–15MB
~177K SLoC