Crates.io | tui-pattern-highlighter |
lib.rs | tui-pattern-highlighter |
version | 0.2.2 |
source | src |
created_at | 2024-05-27 16:43:21.325302 |
updated_at | 2024-08-10 21:01:49.213106 |
description | a dead simple search pattern highlighter for ratatui |
homepage | |
repository | https://github.com/0watcher/tui-pattern-highlighter |
max_upload_size | |
id | 1253562 |
size | 8,715 |
a dead simple search pattern highlighter for ratatui
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);