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

Commit

Permalink
Load themes from internal dump
Browse files Browse the repository at this point in the history
  • Loading branch information
trishume committed Jun 13, 2016
1 parent 4cc2738 commit 562d21e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "testdata/Packages"]
path = testdata/Packages
url = https://github.com/sublimehq/Packages
[submodule "testdata/themes.tmbundle"]
path = testdata/themes.tmbundle
url = https://github.com/textmate/themes.tmbundle.git
[submodule "testdata/InspiredGitHub.tmtheme"]
path = testdata/InspiredGitHub.tmtheme
url = https://github.com/sethlopezme/InspiredGitHub.tmtheme.git
Expand Down
Binary file added assets/default.themedump
Binary file not shown.
9 changes: 9 additions & 0 deletions benches/loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern crate syntect;
use test::Bencher;

use syntect::package_set::PackageSet;
use syntect::theme_set::ThemeSet;

#[bench]
fn bench_load_internal_dump(b: &mut Bencher) {
Expand All @@ -14,6 +15,14 @@ fn bench_load_internal_dump(b: &mut Bencher) {
});
}

#[bench]
fn bench_load_internal_themes(b: &mut Bencher) {
b.iter(|| {
let ts = ThemeSet::load_defaults();
test::black_box(&ts);
});
}

#[bench]
fn bench_load_syntaxes(b: &mut Bencher) {
b.iter(|| {
Expand Down
4 changes: 4 additions & 0 deletions examples/gendata.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extern crate syntect;
use syntect::package_set::PackageSet;
use syntect::theme_set::ThemeSet;
use syntect::dumps::*;

fn main() {
Expand All @@ -10,4 +11,7 @@ fn main() {
let mut ps2 = PackageSet::new();
ps2.load_syntaxes("testdata/Packages", false).unwrap();
dump_to_file(&ps2, "assets/default_nonewlines.packdump").unwrap();

let ts = ThemeSet::load_from_folder("testdata").unwrap();
dump_to_file(&ts, "assets/default.themedump").unwrap();
}
13 changes: 13 additions & 0 deletions src/dumps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use bincode::rustc_serialize::*;
use std::fs::File;
use std::io::{BufReader, BufWriter};
use package_set::PackageSet;
use theme_set::ThemeSet;
use std::path::Path;
use flate2::write::ZlibEncoder;
use flate2::read::ZlibDecoder;
Expand Down Expand Up @@ -68,9 +69,18 @@ impl PackageSet {
}
}

impl ThemeSet {
/// Loads the set of default themes
/// Currently includes Solarized light/dark, Base16 ocean/mocha/eighties and InspiredGithub
pub fn load_defaults() -> ThemeSet {
from_binary(include_bytes!("../assets/default.themedump"))
}
}

#[cfg(test)]
mod tests {
use package_set::PackageSet;
use theme_set::ThemeSet;
use dumps::*;
#[test]
fn can_dump_and_load() {
Expand All @@ -80,5 +90,8 @@ mod tests {
let bin = dump_binary(&ps);
let ps2: PackageSet = from_binary(&bin[..]);
assert_eq!(ps.syntaxes.len(), ps2.syntaxes.len());

let themes = ThemeSet::load_defaults();
assert!(themes.themes.len() > 4);
}
}
2 changes: 1 addition & 1 deletion src/theme_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use walkdir;

#[derive(Debug, RustcEncodable, RustcDecodable)]
pub struct ThemeSet {
themes: BTreeMap<String, Theme>,
pub themes: BTreeMap<String, Theme>,
}

#[derive(Debug)]
Expand Down
1 change: 0 additions & 1 deletion testdata/themes.tmbundle
Submodule themes.tmbundle deleted from c3b783

0 comments on commit 562d21e

Please sign in to comment.