Permalink
Browse files

Load themes from internal dump

  • Loading branch information...
1 parent 4cc2738 commit 562d21e3883cbc54a34a51c6ca34f230393352e3 @trishume committed Jun 13, 2016
Showing with 27 additions and 5 deletions.
  1. +0 −3 .gitmodules
  2. BIN assets/default.themedump
  3. +9 −0 benches/loading.rs
  4. +4 −0 examples/gendata.rs
  5. +13 −0 src/dumps.rs
  6. +1 −1 src/theme_set.rs
  7. +0 −1 testdata/themes.tmbundle
View
@@ -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
Binary file not shown.
View
@@ -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) {
@@ -15,6 +16,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(|| {
let mut ps = PackageSet::new();
View
@@ -1,5 +1,6 @@
extern crate syntect;
use syntect::package_set::PackageSet;
+use syntect::theme_set::ThemeSet;
use syntect::dumps::*;
fn main() {
@@ -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();
}
View
@@ -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;
@@ -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() {
@@ -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);
}
}
View
@@ -10,7 +10,7 @@ use walkdir;
#[derive(Debug, RustcEncodable, RustcDecodable)]
pub struct ThemeSet {
- themes: BTreeMap<String, Theme>,
+ pub themes: BTreeMap<String, Theme>,
}
#[derive(Debug)]
Submodule themes.tmbundle deleted from c3b783

0 comments on commit 562d21e

Please sign in to comment.