@@ -22,7 +22,7 @@ mod terminal;
2222use std::collections::HashMap;
2323use std::env;
2424use std::fs::{self, File};
25−use std::io::{self, BufRead, StdoutLock, Write};
25+use std::io::{self, BufRead, BufReader, StdoutLock, Write};
2626use std::path::Path;
2727use std::process;
2828
@@ -35,7 +35,7 @@ use directories::ProjectDirs;
3535use git2::{DiffOptions, IntoCString, Repository};
3636
3737use syntect::dumps::{dump_to_file, from_binary, from_reader};
38−use syntect::easy::HighlightFile;
38+use syntect::easy::HighlightLines;
3939use syntect::highlighting::{Theme, ThemeSet};
4040use syntect::parsing::SyntaxSet;
4141
@@ -55,8 +55,9 @@ mod errors {
5555
5656use errors::*;
5757
58−struct Options {
58+struct Options<'a> {
5959 true_color: bool,
60+ language: Option<&'a str>,
6061}
6162
6263#[derive(Copy, Clone, Debug)]
@@ -92,7 +93,14 @@ fn print_file<P: AsRef<Path>>(
9293 filename: P,
9394 line_changes: &Option<LineChanges>,
9495) -> Result<()> {
95− let mut highlighter = HighlightFile::new(filename.as_ref(), syntax_set, theme)?;
96+ let reader = BufReader::new(File::open(filename.as_ref())?);
97+ let syntax = match options.language {
98+ Some(language) => syntax_set.syntaxes().iter()
99+ .find(|syntax| syntax.name.eq_ignore_ascii_case(language)),
100+ None => syntax_set.find_syntax_for_file(filename.as_ref())?,
101+ };
102+ let syntax = syntax.unwrap_or_else(|| syntax_set.find_syntax_plain_text());
103+ let mut highlighter = HighlightLines::new(syntax, theme);
96104
97105 let stdout = io::stdout();
98106 let mut handle = stdout.lock();
@@ -113,10 +121,10 @@ fn print_file<P: AsRef<Path>>(
113121
114122 print_horizontal_line(&mut handle, '┼', term_width)?;
115123
116− for (idx, maybe_line) in highlighter.reader.lines().enumerate() {
124+ for (idx, maybe_line) in reader.lines().enumerate() {
117125 let line_nr = idx + 1;
118126 let line = maybe_line.unwrap_or_else(|_| "<INVALID UTF-8>".into());
119− let regions = highlighter.highlight_lines.highlight(&line);
127+ let regions = highlighter.highlight(&line);
120128
121129 let line_change = if let Some(ref changes) = *line_changes {
122130 match changes.get(&(line_nr as u32)) {
@@ -344,6 +352,12 @@ fn run() -> Result<()> {
344352 .setting(AppSettings::DisableVersion)
345353 .max_term_width(90)
346354 .about(crate_description!())
355+ .arg(Arg::with_name("language")
356+ .short("l")
357+ .long("language")
358+ .help("Language of the file(s)")
359+ .takes_value(true)
360+ )
347361 .arg(
348362 Arg::with_name("FILE")
349363 .help("File(s) to print")
@@ -366,6 +380,7 @@ fn run() -> Result<()> {
366380 _ => {
367381 let options = Options {
368382 true_color: is_truecolor_terminal(),
383+ language: app_matches.value_of("language"),
369384 };
370385
371386 let assets =