Struct syntect::easy::HighlightLines
[−]
[src]
pub struct HighlightLines<'a> { /* fields omitted */ }
Simple way to go directly from lines of text to coloured tokens.
Depending on how you load the syntaxes (see the SyntaxSet
docs)
you can either pass this strings with trailing \n
s or without.
Examples
Prints coloured lines of a string to the terminal
use syntect::easy::HighlightLines; use syntect::parsing::SyntaxSet; use syntect::highlighting::{ThemeSet, Style}; use syntect::util::as_24_bit_terminal_escaped; // Load these once at the start of your program let ps = SyntaxSet::load_defaults_nonewlines(); let ts = ThemeSet::load_defaults(); let syntax = ps.find_syntax_by_extension("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 s.lines() { let ranges: Vec<(Style, &str)> = h.highlight(line); let escaped = as_24_bit_terminal_escaped(&ranges[..], true); println!("{}", escaped); }