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

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

API reference · Markdown

tmuxp.cli.search.highlight_matches ( text : str , patterns : list[SearchPattern] , colors : Colors ) → str
function [source]
function [source]
tmuxp.cli.search.highlight_matches

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
  • 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.

Esc

Type to search.