A lightweight translation layer between syntect.rs and tui.rs style types. If you're building a CLI app with a UI powered by tui.rs and need syntax highlighting, then you may find this crate useful!
Given the limited scope of this crate I do have any plans to extend its functionality any further, but am open to contributions. Feel free to fork and submit a pull request.
syntect-tui
is available on crates.io. You can install it by adding the following line to your Cargo.toml
:
syntect-tui = "1.0"
Building upon syntect's simple example, here's a snippet that parses some rust code, highlights it using syntect and converts it into tui::text::Spans ready for rendering in a tui appliction: ``` use syntect::easy::HighlightLines; use syntect::parsing::SyntaxSet; use syntect::highlighting::{ThemeSet, Style}; use syntect::util::LinesWithEndings; use syntui::into_span;
let ps = SyntaxSet::loaddefaultsnewlines();
let ts = ThemeSet::loaddefaults();
let syntax = ps.findsyntaxbyextension("rs").unwrap();
let mut h = HighlightLines::new(syntax, &ts.themes["base16-ocean.dark"]);
let s = "pub struct Wow { hi: u64 }\nfn blah() -> u64 {}";
for line in LinesWithEndings::from(s) { // LinesWithEndings enables use of newlines mode
let linespans: Vec
```
Thanks to trishume and https://github.com/fdehau/ for building sytect
& tui
! All code is released under the MIT License.