tmuxp.cli.search.highlight_matches
Python
- Python
- Ruby Unavailable
- Lua Unavailable
- TypeScript Unavailable
- Rust Unavailable
- Go Unavailable
- Java Unavailable
- .NET Unavailable
- C++ Unavailable
- Swift Unavailable
- tmuxp.cli.search.highlight_matches ( text : str , patterns : list[SearchPattern] , colors : Colors ) str
-
Highlight regex matches in text.
Examples
>>> from tmuxp.cli._colors import ColorMode, Colors>>> colors = Colors(ColorMode.NEVER)>>> pattern = SearchPattern(... fields=("name",),... raw="dev",... regex=re.compile("dev"),... )>>> highlight_matches("development", [pattern], colors=colors)'development'With colors enabled (ALWAYS mode):
>>> colors_on = Colors(ColorMode.ALWAYS)>>> result = highlight_matches("development", [pattern], colors=colors_on)>>> "dev" in resultTrue>>> chr(27) in result # Contains ANSI escapeTrue- Parameters
-
-
text ( str ) – Text to search and highlight.
-
patterns ( list[SearchPattern] ) – Compiled search patterns (uses their regex attribute).
-
colors ( Colors ) – Color manager for highlighting.
-
- Returns
-
str Text with matches highlighted, or original text if no matches.