-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fonts are now parsed from a file. major restructuring.
- Loading branch information
1 parent
d7e5ac6
commit 18559b5
Showing
11 changed files
with
470 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
[package] | ||
name = "glyphrs" | ||
version = "0.1.3" | ||
version = "0.1.4" | ||
edition = "2021" | ||
license = "MIT" | ||
description = "A text art generator written in Rust" | ||
|
||
[dependencies] | ||
clap = "4.5.4" | ||
clap = "4.5.4" | ||
serde = { version = "1.0.203", features = ["derive"] } | ||
toml = "0.8.13" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::collections::HashMap; | ||
use serde::Deserialize; | ||
|
||
|
||
#[derive(Debug, Deserialize)] | ||
struct Outer { | ||
fonts: Vec<Font>, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct Font { | ||
name: String, | ||
character: Vec<char>, | ||
key_values: Vec<Vec<String>>, | ||
} | ||
|
||
|
||
|
||
|
||
pub fn get_fonts() -> Vec<String> { | ||
let fonts = define_fonts(); | ||
let mut font_list: Vec<String> = vec![]; | ||
|
||
for keys in fonts.keys().cloned() { | ||
font_list.push(keys); | ||
} | ||
|
||
font_list | ||
} | ||
|
||
fn get_font_file() -> &'static str { | ||
let file = include_bytes!("./fonts.toml"); | ||
let contents = std::str::from_utf8(file).expect("Failed to read config.toml"); | ||
|
||
contents | ||
} | ||
|
||
pub fn define_fonts() -> HashMap<String, HashMap<char, Vec<String>>> { | ||
let mut fonts: HashMap<String, HashMap<char, Vec<String>>> = HashMap::new(); | ||
let contents = get_font_file(); | ||
let toml_value: Outer =toml::from_str(&contents).expect("Failed to parse config.toml"); | ||
|
||
for font in toml_value.fonts { | ||
let mut font_map: HashMap<char, Vec<String>> = HashMap::new(); | ||
for i in 0..font.character.len() { | ||
let key = font.character[i]; | ||
let value = &font.key_values[i]; | ||
font_map.insert(key, value.to_vec()); | ||
} | ||
|
||
fonts.insert(font.name, font_map); | ||
} | ||
fonts | ||
} |
Oops, something went wrong.