Skip to content

Commit c6c908c

Browse files
committed
Add the ability to list resources used by a yaml file.
1 parent 0cf4af5 commit c6c908c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

wrench/src/args.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ subcommands:
7878
help: Include the given element type. Can be specified multiple times. (rect/image/text/glyphs/border)
7979
multiple: true
8080
takes_value: true
81+
- list-resources:
82+
long: list-resources
83+
help: List the resources used by this YAML file
8184
- watch:
8285
short: w
8386
long: watch

wrench/src/yaml_frame_reader.rs

+6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ pub struct YamlFrameReader {
154154
include_only: Vec<String>,
155155

156156
watch_source: bool,
157+
list_resources: bool,
157158

158159
/// A HashMap of offsets which specify what scroll offsets particular
159160
/// scroll layers should be initialized with.
@@ -170,6 +171,7 @@ impl YamlFrameReader {
170171
pub fn new(yaml_path: &Path) -> YamlFrameReader {
171172
YamlFrameReader {
172173
watch_source: false,
174+
list_resources: false,
173175
frame_built: false,
174176
yaml_path: yaml_path.to_owned(),
175177
aux_dir: yaml_path.parent().unwrap().to_owned(),
@@ -207,6 +209,7 @@ impl YamlFrameReader {
207209
let yaml_file = args.value_of("INPUT").map(|s| PathBuf::from(s)).unwrap();
208210

209211
let mut y = YamlFrameReader::new(&yaml_file);
212+
y.list_resources = args.is_present("list-resources");
210213
y.watch_source = args.is_present("watch");
211214
y.queue_depth = args.value_of("queue")
212215
.map(|s| s.parse::<u32>().unwrap())
@@ -308,6 +311,7 @@ impl YamlFrameReader {
308311
return *k;
309312
}
310313

314+
if self.list_resources { println!("{}", file.to_string_lossy()); }
311315
let (descriptor, image_data) = match image::open(file) {
312316
Ok(image) => {
313317
let image_dims = image.dimensions();
@@ -373,13 +377,15 @@ impl YamlFrameReader {
373377
}
374378

375379
fn get_or_create_font(&mut self, desc: FontDescriptor, wrench: &mut Wrench) -> FontKey {
380+
let list_resources = self.list_resources;
376381
*self.fonts
377382
.entry(desc.clone())
378383
.or_insert_with(|| match desc {
379384
FontDescriptor::Path {
380385
ref path,
381386
font_index,
382387
} => {
388+
if list_resources { println!("{}", path.to_string_lossy()); }
383389
let mut file = File::open(path).expect("Couldn't open font file");
384390
let mut bytes = vec![];
385391
file.read_to_end(&mut bytes)

0 commit comments

Comments
 (0)