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 |
#608 in Command-line interface
48 downloads per month
8KB
88 lines
tui-pattern-highlighter
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–14MB
~177K SLoC