Skip to content
This repository has been archived by the owner on Feb 12, 2018. It is now read-only.

Commit

Permalink
defunct highlight files
Browse files Browse the repository at this point in the history
  • Loading branch information
trishume committed Jun 16, 2016
1 parent 5d21b9a commit 75f0451
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/easy.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -58,6 +61,25 @@ impl<'a> HighlightLines<'a> {
}
}

pub struct HighlightFile<'a> {
reader: BufReader<File>,
line_highlighter: HighlightLines<'a>,
}

impl<'a> HighlightFile<'a> {
pub fn new<P: AsRef<Path>>(path_obj: P, ss: &SyntaxSet, theme: &'a Theme) -> io::Result<HighlightFile<'a>> {
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::*;
Expand Down

0 comments on commit 75f0451

Please sign in to comment.