Struct syntect::easy::HighlightFile
[−]
[src]
pub struct HighlightFile<'a> { pub reader: BufReader<File>, pub highlight_lines: HighlightLines<'a>, }
Convenience struct containing everything you need to highlight a file.
Use the reader
to get the lines of the file and the highlight_lines
to highlight them.
See the new
method docs for more information.
Fields
reader: BufReader<File>
highlight_lines: HighlightLines<'a>
Methods
impl<'a> HighlightFile<'a>
[src]
fn new<P: AsRef<Path>>(path_obj: P, ss: &SyntaxSet, theme: &'a Theme) -> Result<HighlightFile<'a>>
Constructs a file reader and a line highlighter to get you reading files as fast as possible.
Auto-detects the syntax from the extension and constructs a HighlightLines
with the correct syntax and theme.
Examples
use syntect::parsing::SyntaxSet; use syntect::highlighting::{ThemeSet, Style}; use syntect::util::as_24_bit_terminal_escaped; use syntect::easy::HighlightFile; use std::io::BufRead; let ss = SyntaxSet::load_defaults_nonewlines(); let ts = ThemeSet::load_defaults(); let mut highlighter = HighlightFile::new("testdata/highlight_test.erb", &ss, &ts.themes["base16-ocean.dark"]).unwrap(); for maybe_line in highlighter.reader.lines() { let line = maybe_line.unwrap(); let regions: Vec<(Style, &str)> = highlighter.highlight_lines.highlight(&line); println!("{}", as_24_bit_terminal_escaped(®ions[..], true)); }