Workspace ManagerstableAPI Reference

Choose documentation 3

stable

Current version

stable
English

Prerelease This site documents an alpha of libtmux. Its structure, URLs and APIs are subject to change.

tmuxp.cli.search.highlight_matches

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 result
True
>>> chr(27) in result # Contains ANSI escape
True
Parameters
Returns

str Text with matches highlighted, or original text if no matches.

Esc

Type to search.

Reference preview Open reference