@@ -1,3 +1,4 @@
1+use assets::HighlightingAssets;
12use atty::{self, Stream};
23use clap::{App as ClapApp, AppSettings, Arg, ArgGroup, ArgMatches, SubCommand};
34use console::Term;
@@ -282,7 +283,18 @@ impl App {
282283 },
283284 term_width: Term::stdout().size().1 as usize,
284285 files,
285− theme: self.matches.value_of("theme"),
286+ theme: self.matches
287+ .value_of("theme")
288+ .and_then(|theme_name_arg| Some(String::from(theme_name_arg)))
289+ .or_else(|| {
290+ env::var("BAT_THEME").ok().and_then(|theme_name_env| {
291+ if HighlightingAssets::new().theme_exists(&theme_name_env) {
292+ Some(theme_name_env)
293+ } else {
294+ None
295+ }
296+ })
297+ }),
286298 line_range: transpose(self.matches.value_of("line-range").map(LineRange::from))?,
287299 })
288300 }
@@ -336,7 +348,7 @@ pub struct Config<'a> {
336348 pub paging_mode: PagingMode,
337349 pub term_width: usize,
338350 pub files: Vec<Option<&'a str>>,
339− pub theme: Option<&'a str>,
351+ pub theme: Option<String>,
340352 pub line_range: Option<LineRange>,
341353}
342354