worked on adding path

This commit is contained in:
spiders 2022-05-06 21:28:33 -07:00
parent b291745a3e
commit 917fd95770
2 changed files with 73 additions and 19 deletions

View file

@ -1,4 +1,5 @@
use super::kule::*;
use std::env;
use std::fs;
use std::io;
use voca_rs::*;
@ -158,7 +159,7 @@ $8 |||| $9$0"
"kijetesantakalu" => (),
"lili" => config.template = kijetesantakalu_little,
"soweli" => config.template = soweli,
name => config.template = template_from_file(&name)?,
name => config.template = CritterConfig::template_from_file(&name)?,
}
}
@ -181,10 +182,8 @@ $8 |||| $9$0"
.replace("$9", &reset())
.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> {
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
@ -203,3 +202,45 @@ pub fn template_from_file(name: &str) -> Result<CritterTemplate, &str> {
Ok(CritterTemplate { anchor, critter })
}
}
fn path() -> Vec<String> {
match env::var("NASINKIJE") {
Err(_) => Vec::new(),
Ok(s) => s.split(":").map(|s| s.to_string()).collect(),
}
}
fn list_files() -> Result<Vec<String>, String> {
let mut files = Vec::new();
for i in path() {
match fs::read_dir(&i) {
Err(e) => match e.kind() {
io::ErrorKind::PermissionDenied => {
return Err(
format!("mi ken ala lukin e poki ni: {}\npermission denied", i).to_string(),
)
}
io::ErrorKind::NotFound => {
return Err(format!(
"poki ni li lon ala: {}\ndirectory not found",
i.to_string()
))
}
_ => return Err(format!("ijo li pakala lon ni: {}\n{:?}", i, e.kind()).to_string()),
},
Ok(entries) => {
for read in entries {
let filename = read
.map_err(|e|format!("mi ken ala lukin e lipu lon ni: {}\n{}", i, e.to_string()).to_string())?
.file_name()
.into_string()
.map_err(|_|format!("mi ken ala sitelen UTF-8 e nimi lipu lon ni: {}\ncould not display file name as utf-8", i).to_string())?;
files.push(filename);
}
}
}
}
return Ok(files);
}

13
yupekosi Normal file
View file

@ -0,0 +1,13 @@
# yupekosi
# tan kulupu lintukamakaki
20
$9$7
$8 ////\|///\ $9$5
$8 ///\\\||///\ $9$7
$8 // _ _ \\ $9$6
$8 _||-($1)--($2)-||_ $9$5
$8( || () || )
\ \\ ///\\\ // /
-// ||$3$4|| \\-
\\///||\\\//
\\\\||////$9 $0