tui-syntax-highlight
A library for creating code blocks in
ratatui apps with
syntect.

Feature Flags
Note: One of regex-onig or regex-fancy is required or syntect will not
compile.
-
regex-onig- Uses theonigregex engine (enabled by default). See syntect's documentation for more info. -
regex-fancy- Uses thefancy-regexregex engine. See syntect's documentation for more info. -
termprofile- Enables integration withtermprofileto detect the terminal's color support level and automatically use compatible colors.
Usage
Use Highlighter to return a Ratatui Text object containing the highlighted
content.
Highlighting a File
use Error;
use File;
use ThemeSet;
use SyntaxSet;
use Highlighter;
Highlighting Text
use Error;
use File;
use ThemeSet;
use SyntaxSet;
use LinesWithEndings;
use Highlighter;
Additional Themes
The syntect-assets crate provides
additional themes and syntaxes that are compatible with syntect. It contains a
few themes like ansi, base16, and base16-256 that encodes colors in a
special way - these special encodings are handled automatically by this crate.
Custom Themes and Syntaxes
Custom themes and syntaxes can be compiled and embedded in the binary. See the
sqlite_custom
example for usage.
Code Block Style
Settings such as the background color, formatting, and line number style can all
be changed. See the available methods in
Highlighter
for details.
Supported Rust Versions
The MSRV is currently 1.88.0. Since Cargo's V3 resolver supports MSRV-aware dependencies, we do not treat an MSRV bump as a breaking change.