-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbuild.rs
More file actions
111 lines (99 loc) · 4.12 KB
/
build.rs
File metadata and controls
111 lines (99 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use std::fs::{self, File};
use std::io::Write;
use std::path::Path;
include!("src/core/library/settings/theme.rs");
fn main() {
embed_themes();
}
fn embed_themes() {
let mut themes = Vec::new();
for entry in fs::read_dir("res/themes").unwrap() {
let entry = entry.unwrap();
let path = entry.path();
if path.is_file() {
let content = fs::read_to_string(&path).unwrap();
let theme: Theme = toml::from_str(&content).unwrap();
themes.push(theme);
}
}
themes.sort_by_key(|t| t.scheme.to_lowercase());
let out_path = Path::new("src/core/library/settings/themedata.rs");
{
let mut out = File::create(out_path).unwrap();
writeln!(out, "// This is a generated file. Check `build.rs`").unwrap();
writeln!(out, "use crate::core::library::settings::theme::Theme;\n").unwrap();
writeln!(out, "use std::collections::HashMap;").unwrap();
writeln!(out, "pub fn get_themes() -> HashMap<String, Theme> {{").unwrap();
writeln!(out, " let mut m = HashMap::new();").unwrap();
for theme in themes.iter_mut() {
theme.base[0] = u32::from_str_radix(&theme.base00, 16).unwrap();
theme.base[1] = u32::from_str_radix(&theme.base01, 16).unwrap();
theme.base[2] = u32::from_str_radix(&theme.base02, 16).unwrap();
theme.base[3] = u32::from_str_radix(&theme.base03, 16).unwrap();
theme.base[4] = u32::from_str_radix(&theme.base04, 16).unwrap();
theme.base[5] = u32::from_str_radix(&theme.base05, 16).unwrap();
theme.base[6] = u32::from_str_radix(&theme.base06, 16).unwrap();
theme.base[7] = u32::from_str_radix(&theme.base07, 16).unwrap();
theme.base[8] = u32::from_str_radix(&theme.base08, 16).unwrap();
theme.base[9] = u32::from_str_radix(&theme.base09, 16).unwrap();
theme.base[10] = u32::from_str_radix(&theme.base0A, 16).unwrap();
theme.base[11] = u32::from_str_radix(&theme.base0B, 16).unwrap();
theme.base[12] = u32::from_str_radix(&theme.base0C, 16).unwrap();
theme.base[13] = u32::from_str_radix(&theme.base0D, 16).unwrap();
theme.base[14] = u32::from_str_radix(&theme.base0E, 16).unwrap();
theme.base[15] = u32::from_str_radix(&theme.base0F, 16).unwrap();
writeln!(
out,
" m.insert(
\"{}\".to_string(),
Theme {{
scheme: \"{}\".to_string(),
author: \"{}\".to_string(),
base00: \"{}\".to_string(),
base01: \"{}\".to_string(),
base02: \"{}\".to_string(),
base03: \"{}\".to_string(),
base04: \"{}\".to_string(),
base05: \"{}\".to_string(),
base06: \"{}\".to_string(),
base07: \"{}\".to_string(),
base08: \"{}\".to_string(),
base09: \"{}\".to_string(),
base0A: \"{}\".to_string(),
base0B: \"{}\".to_string(),
base0C: \"{}\".to_string(),
base0D: \"{}\".to_string(),
base0E: \"{}\".to_string(),
base0F: \"{}\".to_string(),",
theme.scheme,
theme.scheme,
theme.author,
theme.base00,
theme.base01,
theme.base02,
theme.base03,
theme.base04,
theme.base05,
theme.base06,
theme.base07,
theme.base08,
theme.base09,
theme.base0A,
theme.base0B,
theme.base0C,
theme.base0D,
theme.base0E,
theme.base0F
)
.unwrap();
writeln!(out, " base: {:?},", theme.base).unwrap();
writeln!(out, " }},\n );").unwrap();
}
writeln!(out, " m").unwrap();
writeln!(out, "}}").unwrap();
}
std::process::Command::new("rustfmt")
.arg(out_path)
.status()
.expect("Failed to run rustfmt");
}