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

Commit

Permalink
load theme from streams
Browse files Browse the repository at this point in the history
  • Loading branch information
TyOverby committed Jul 11, 2016
1 parent b62ce67 commit 0696f7e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/highlighting/theme_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::settings::*;
use super::super::LoadingError;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use std::io::BufReader;
use std::io::{BufReader, BufRead, Seek};
use walkdir::WalkDir;
use std::fs::File;

Expand All @@ -26,18 +26,16 @@ impl ThemeSet {
Ok(themes)
}

fn read_file(path: &Path) -> Result<BufReader<File>, LoadingError> {
let reader = try!(File::open(path));
Ok(BufReader::new(reader))
}

fn read_plist(path: &Path) -> Result<Settings, LoadingError> {
Ok(try!(read_plist(try!(Self::read_file(path)))))
}

/// Loads a theme given a path to a .tmTheme file
pub fn get_theme<P: AsRef<Path>>(path: P) -> Result<Theme, LoadingError> {
Ok(try!(Theme::parse_settings(try!(Self::read_plist(path.as_ref())))))
let file = try!(File::open(path));
let mut file = BufReader::new(file);
Self::load_from_reader(&mut file)
}

/// Loads a theme given a readable stream
pub fn load_from_reader<R: BufRead + Seek>(r: &mut R) -> Result<Theme, LoadingError> {
Ok(try!(Theme::parse_settings(try!(read_plist(r)))))
}

/// Loads all the themes in a folder
Expand Down

0 comments on commit 0696f7e

Please sign in to comment.