From 75f04515159d610e13692ee56d34be8d1d4164fb Mon Sep 17 00:00:00 2001 From: Tristan Hume Date: Wed, 15 Jun 2016 20:13:54 -0400 Subject: [PATCH] defunct highlight files --- src/easy.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/easy.rs b/src/easy.rs index 2786b269..eb359261 100644 --- a/src/easy.rs +++ b/src/easy.rs @@ -1,5 +1,8 @@ -use parsing::{ScopeStack, ParseState, SyntaxDefinition}; +use parsing::{ScopeStack, ParseState, SyntaxDefinition, SyntaxSet}; use highlighting::{Highlighter, HighlightState, HighlightIterator, Theme, Style}; +use std::io::{BufReader, self}; +use std::fs::File; +use std::path::Path; // use util::debug_print_ops; /// Simple way to go directly from lines of text to coloured @@ -58,6 +61,25 @@ impl<'a> HighlightLines<'a> { } } +pub struct HighlightFile<'a> { + reader: BufReader, + line_highlighter: HighlightLines<'a>, +} + +impl<'a> HighlightFile<'a> { + pub fn new>(path_obj: P, ss: &SyntaxSet, theme: &'a Theme) -> io::Result> { + let path: &Path = path_obj.as_ref(); + let extension = path.extension().and_then(|x| x.to_str()).unwrap_or(""); + let mut f = try!(File::open(path)); + let reader = BufReader::new(f); + let syntax = ss.find_syntax_by_extension(extension).unwrap(); + Ok(HighlightFile { + reader: reader, + line_highlighter: HighlightLines::new(syntax, theme), + }) + } +} + #[cfg(test)] mod tests { use super::*;