added preliminary kijefiles support
This commit is contained in:
parent
305fa2e673
commit
b291745a3e
|
@ -160,7 +160,7 @@ impl BubbleConfig {
|
||||||
" ",
|
" ",
|
||||||
);
|
);
|
||||||
let bubble_bottom = manipulate::pad_left(
|
let bubble_bottom = manipulate::pad_left(
|
||||||
&format!(" {} ", self.bottom.repeat(longest_length + 2),),
|
&format!(" {} \n", self.bottom.repeat(longest_length + 2),),
|
||||||
left_pad_length,
|
left_pad_length,
|
||||||
" ",
|
" ",
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use super::kule::*;
|
use super::kule::*;
|
||||||
|
use std::fs;
|
||||||
|
use std::io;
|
||||||
use voca_rs::*;
|
use voca_rs::*;
|
||||||
|
|
||||||
// represents inherent structural information about a critter
|
// represents inherent structural information about a critter
|
||||||
|
@ -45,11 +47,10 @@ impl CritterConfig {
|
||||||
object: &Option<String>,
|
object: &Option<String>,
|
||||||
format: &Option<String>,
|
format: &Option<String>,
|
||||||
name: &Option<String>,
|
name: &Option<String>,
|
||||||
) -> CritterConfig {
|
) -> Result<CritterConfig, String> {
|
||||||
let kijetesantakalu = CritterTemplate {
|
let kijetesantakalu = CritterTemplate {
|
||||||
anchor: 14,
|
anchor: 14,
|
||||||
critter: r"
|
critter: r"$8 $9$6
|
||||||
$8 $9$6
|
|
||||||
$8 /__ $9$6
|
$8 /__ $9$6
|
||||||
$8 / $1$2\ $9$5
|
$8 / $1$2\ $9$5
|
||||||
$8 | |$3$4
|
$8 | |$3$4
|
||||||
|
@ -59,8 +60,7 @@ $8 (III|\|| $9$0"
|
||||||
};
|
};
|
||||||
let kijetesantakalu_little = CritterTemplate {
|
let kijetesantakalu_little = CritterTemplate {
|
||||||
anchor: 13,
|
anchor: 13,
|
||||||
critter: r"
|
critter: r"$8 $9$6
|
||||||
$8 $9$6
|
|
||||||
$8 /__ $9$6
|
$8 /__ $9$6
|
||||||
$8 / $1$2\ $9$5
|
$8 / $1$2\ $9$5
|
||||||
$8 | |$3$4
|
$8 | |$3$4
|
||||||
|
@ -69,8 +69,7 @@ $8 (I|\|| $9$0"
|
||||||
};
|
};
|
||||||
let soweli = CritterTemplate {
|
let soweli = CritterTemplate {
|
||||||
anchor: 10,
|
anchor: 10,
|
||||||
critter: r"
|
critter: r"$8 $9$6
|
||||||
$8 $9$6
|
|
||||||
$8 ___ $9$6
|
$8 ___ $9$6
|
||||||
$8 $1$2) $9$5
|
$8 $1$2) $9$5
|
||||||
$8 |||| $9$0"
|
$8 |||| $9$0"
|
||||||
|
@ -159,11 +158,11 @@ $8 |||| $9$0"
|
||||||
"kijetesantakalu" => (),
|
"kijetesantakalu" => (),
|
||||||
"lili" => config.template = kijetesantakalu_little,
|
"lili" => config.template = kijetesantakalu_little,
|
||||||
"soweli" => config.template = soweli,
|
"soweli" => config.template = soweli,
|
||||||
_ => (),
|
name => config.template = template_from_file(&name)?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return Ok(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// gives a fully formatted version of the critter
|
// gives a fully formatted version of the critter
|
||||||
|
@ -183,3 +182,24 @@ $8 |||| $9$0"
|
||||||
.replace("$0", &self.object);
|
.replace("$0", &self.object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// attempts to interpret file as a path, and if this fails, tries appending it to every location in the kijepath environment variable.
|
||||||
|
pub fn template_from_file(name: &str) -> Result<CritterTemplate, &str> {
|
||||||
|
let file = fs::read_to_string(name)
|
||||||
|
.map_err(|_| "mi ken ala lukin e lipu kije\ncouldn't find/read kijefile")?;
|
||||||
|
let mut lines = file.lines().skip_while(|l| l.starts_with('#')); // skips comments
|
||||||
|
|
||||||
|
let anchor: usize;
|
||||||
|
if let Some(anchor_line) = lines.next() {
|
||||||
|
anchor = anchor_line
|
||||||
|
.trim()
|
||||||
|
.parse()
|
||||||
|
.map_err(|_| "nanpa li nasa\ncouldn't parse anchor as number")?;
|
||||||
|
} else {
|
||||||
|
return Err("ale li weka tan lipu kije\nkijefile missing content");
|
||||||
|
}
|
||||||
|
let mut critter = String::new();
|
||||||
|
lines.for_each(|l| critter.push_str(&format!("{}\n", l)));
|
||||||
|
|
||||||
|
Ok(CritterTemplate { anchor, critter })
|
||||||
|
}
|
||||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -21,8 +21,16 @@ use voca_rs::*;
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Args::parse();
|
let cli = Args::parse();
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
let (critter_config, bubble_config) = cli.configs_from_arguments();
|
let (critter_config, bubble_config);
|
||||||
|
match cli.configs_from_arguments() {
|
||||||
|
Err(s) => {
|
||||||
|
println!("pakala a!\n{}", s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Ok((c, b)) => {
|
||||||
|
(critter_config, bubble_config) = (c, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
if !cli.text.is_empty() {
|
if !cli.text.is_empty() {
|
||||||
text = cli.text.join(" ")
|
text = cli.text.join(" ")
|
||||||
} else {
|
} else {
|
||||||
|
@ -104,7 +112,7 @@ struct Args {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args {
|
impl Args {
|
||||||
fn configs_from_arguments(&self) -> (CritterConfig, BubbleConfig) {
|
fn configs_from_arguments(&self) -> Result<(CritterConfig, BubbleConfig), String> {
|
||||||
let mut eyes = self.lukin.clone();
|
let mut eyes = self.lukin.clone();
|
||||||
let mut tongue = self.uta.clone();
|
let mut tongue = self.uta.clone();
|
||||||
let mut line = self.palisa.clone();
|
let mut line = self.palisa.clone();
|
||||||
|
@ -206,8 +214,14 @@ impl Args {
|
||||||
_ => String::new(),
|
_ => String::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
let critter_config =
|
let critter_config = CritterConfig::config_from_string(
|
||||||
CritterConfig::config_from_string(&eyes, &tongue, &line, &object, &Some(format), &name);
|
&eyes,
|
||||||
|
&tongue,
|
||||||
|
&line,
|
||||||
|
&object,
|
||||||
|
&Some(format),
|
||||||
|
&name,
|
||||||
|
)?;
|
||||||
let bubble_config = BubbleConfig::config_from_string(
|
let bubble_config = BubbleConfig::config_from_string(
|
||||||
critter_config.template.anchor,
|
critter_config.template.anchor,
|
||||||
self.pakala,
|
self.pakala,
|
||||||
|
@ -215,7 +229,7 @@ impl Args {
|
||||||
&border,
|
&border,
|
||||||
);
|
);
|
||||||
|
|
||||||
(critter_config, bubble_config)
|
Ok((critter_config, bubble_config))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue