Skip to content

Commit

Permalink
v0.1.4
Browse files Browse the repository at this point in the history
fonts are now parsed from a file.
major restructuring.
  • Loading branch information
Localghost385 committed May 27, 2024
1 parent d7e5ac6 commit 18559b5
Show file tree
Hide file tree
Showing 11 changed files with 470 additions and 109 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### v0.1.4
- major restructuring.
- fonts are now parsed from a toml file, so they are easier to add.

### v0.1.3
- cargo doesnt like my versioning

Expand Down
139 changes: 138 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
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"
12 changes: 9 additions & 3 deletions src/clap.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use clap::*;

use crate::fonts::*;

fn string_to_str(input: Vec<String>) -> Vec<&'static str> {
let mut output: Vec<&'static str> = Vec::with_capacity(input.len());
for s in input {
output.push(Box::leak(s.into_boxed_str()));
}
output
}

use crate::fonts::font_handling::*;

pub fn clap_parse() -> ArgMatches {
let cmd = clap::Command::new("cargo")
Expand All @@ -19,7 +25,7 @@ pub fn clap_parse() -> ArgMatches {
.long("font")
.short('f')
.default_value("blocks_in_two_lines")
.value_parser(get_fonts())
.value_parser(string_to_str(get_fonts()))
.help("set the font"),

)
Expand Down
66 changes: 0 additions & 66 deletions src/fonts.rs

This file was deleted.

54 changes: 54 additions & 0 deletions src/fonts/font_handling.rs
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
}
Loading

0 comments on commit 18559b5

Please sign in to comment.