added clap as a dependency,

did a pair programming session with arty which resulted in some changes to critter config types

still need to fix config_from_string to take the new option types into account
This commit is contained in:
spiders 2022-04-25 22:19:48 -07:00
parent f04e237735
commit 1fd5b98c7f
4 changed files with 289 additions and 43 deletions

223
Cargo.lock generated
View file

@ -11,10 +11,104 @@ dependencies = [
"memchr",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "clap"
version = "3.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c167e37342afc5f33fd87bbc870cedd020d2a6dffa05d45ccd9241fbdd146db"
dependencies = [
"atty",
"bitflags",
"clap_derive",
"clap_lex",
"indexmap",
"lazy_static",
"strsim",
"termcolor",
"textwrap",
]
[[package]]
name = "clap_derive"
version = "3.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "189ddd3b5d32a70b35e7686054371742a937b0d99128e76dde6340210e966669"
dependencies = [
"os_str_bytes",
]
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "heck"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "indexmap"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]]
name = "kijetesantakaluotokieni"
version = "0.1.0"
dependencies = [
"clap",
"voca_rs",
]
@ -24,12 +118,66 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.124"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50"
[[package]]
name = "memchr"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]]
name = "os_str_bytes"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec757218438d5fda206afc041538b2f6d889286160d649a86a24d37e1235afd1"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.5.5"
@ -57,12 +205,56 @@ dependencies = [
"regex",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b683b2b825c8eef438b77c36a06dc262294da3d5a5813fac20da149241dcd44d"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "termcolor"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
[[package]]
name = "unicode-segmentation"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "voca_rs"
version = "1.14.0"
@ -73,3 +265,34 @@ dependencies = [
"stfu8",
"unicode-segmentation",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View file

@ -1,10 +1,12 @@
[package]
author = "kulupu lintukamaki"
name = "kijetesantakaluotokieni"
version = "0.1.0"
edition = "2021"
about = "kijetesantakalu toki tawa ilo sona sina"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
voca_rs = " 1.14.0"
clap = { version = "3.1.12", features = ["derive"] }

View file

@ -1,10 +1,17 @@
use voca_rs::*;
pub struct Critter<'a> {
pub anchor: usize,
pub critter: &'a str,
pub enum CritterName {
Kije,
Little,
File(String),
}
#[derive(Clone)]
pub struct CritterTemplate {
pub anchor: usize,
pub critter: String,
}
#[derive(Clone)]
pub struct CritterConfig {
pub left_eye: String,
pub right_eye: String,
@ -15,31 +22,34 @@ pub struct CritterConfig {
pub right_line: String,
pub up_line: String,
pub left_line: String,
pub template: CritterTemplate,
}
pub const KIJETESANTAKALU: Critter = Critter {
const KIJETESANTAKALU: CritterTemplate = CritterTemplate {
anchor: 14,
critter: r"
$6
/__ $6
/ $1$2\ $7
/ $1$2\ $5
| |$3$4
| |
(III|\||",
(III|\||"
.to_string(),
};
pub const KIJETESANTAKALU_LITTLE: Critter = Critter {
const KIJETESANTAKALU_LITTLE: CritterTemplate = CritterTemplate {
anchor: 13,
critter: r"
$6
/__ $6
/ $1$2\ $5
| |$3$4
(I|\||",
(I|\||"
.to_string(),
};
pub fn config_from_string(eyes: &str, tongue: &str, line: &str) -> CritterConfig {
let default_config = CritterConfig {
const DEFAULT_CONFIG: CritterConfig = CritterConfig {
left_eye: String::from("."),
right_eye: String::from("."),
@ -49,20 +59,26 @@ pub fn config_from_string(eyes: &str, tongue: &str, line: &str) -> CritterConfig
right_line: String::from("/"),
up_line: String::from("|"),
left_line: String::from("\\"),
};
let (left_eye, right_eye);
let (left_tongue, right_tongue);
let (left_line, up_line, right_line);
template: KIJETESANTAKALU,
};
pub fn config_from_string(
eyes: Option<&str>,
tongue: Option<&str>,
line: Option<&str>,
) -> CritterConfig {
let mut config = DEFAULT_CONFIG.clone();
match count::count_graphemes(eyes) {
0 => (left_eye, right_eye) = (default_config.left_eye, default_config.right_eye),
0 => break,
1 => (left_eye, right_eye) = (chop::grapheme_at(eyes, 0), chop::grapheme_at(eyes, 0)),
_ => (left_eye, right_eye) = (chop::grapheme_at(eyes, 0), chop::grapheme_at(eyes, 1)),
}
match count::count_graphemes(tongue) {
0 => {
(left_tongue, right_tongue) = (default_config.left_tongue, default_config.right_tongue)
(left_tongue, right_tongue) = (DEFAULT_CONFIG.left_tongue, DEFAULT_CONFIG.right_tongue)
}
1 => (left_tongue, right_tongue) = (chop::grapheme_at(tongue, 0), " ".to_string()),
_ => {
@ -73,23 +89,23 @@ pub fn config_from_string(eyes: &str, tongue: &str, line: &str) -> CritterConfig
match count::count_graphemes(line) {
0 => {
(left_line, up_line, right_line) = (
default_config.left_line,
default_config.up_line,
default_config.right_line,
DEFAULT_CONFIG.left_line,
DEFAULT_CONFIG.up_line,
DEFAULT_CONFIG.right_line,
)
}
1 => {
(left_line, up_line, right_line) = (
chop::grapheme_at(line, 0),
default_config.up_line,
default_config.right_line,
DEFAULT_CONFIG.up_line,
DEFAULT_CONFIG.right_line,
)
}
2 => {
(left_line, up_line, right_line) = (
chop::grapheme_at(line, 0),
chop::grapheme_at(line, 1),
default_config.right_line,
DEFAULT_CONFIG.right_line,
)
}
_ => {
@ -100,17 +116,8 @@ pub fn config_from_string(eyes: &str, tongue: &str, line: &str) -> CritterConfig
)
}
}
CritterConfig {
left_eye,
right_eye,
left_tongue,
right_tongue,
right_line,
up_line,
left_line,
}
return config;
}
pub fn format_critter(critter: &str, critter_config: CritterConfig) -> String {

View file

@ -8,16 +8,30 @@ TO DO
mod bubbles;
mod critters;
use clap::Parser;
use std::io;
use std::io::Read;
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
#[clap(short, long)]
lukin: Option<String>,
#[clap(short, long)]
uta: Option<String>,
#[clap(short, long)]
palisa: Option<String>,
}
fn main() {
let cli = Args::parse();
let mut text = String::new();
let default_config = critters::config_from_string("", "", "");
io::stdin()
.read_to_string(&mut text)
.expect("failed to read input");
// io::stdin()
// .read_to_string(&mut text)
// .expect("failed to read input");
print!(
"{}",