From 44987651bd735f67a361ec07efc86aadcd079fa7 Mon Sep 17 00:00:00 2001 From: AnthonyMichaelTDM <68485672+AnthonyMichaelTDM@users.noreply.github.com> Date: Wed, 9 Mar 2022 13:18:24 -0800 Subject: [PATCH 1/3] added more features to the todo list maker added ability to print only select languages if they choose language first formatting --- 00_Utilities/mardown_todo_rust/src/main.rs | 89 ++++++++++++++-------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/00_Utilities/mardown_todo_rust/src/main.rs b/00_Utilities/mardown_todo_rust/src/main.rs index 8de38175..9b461d24 100644 --- a/00_Utilities/mardown_todo_rust/src/main.rs +++ b/00_Utilities/mardown_todo_rust/src/main.rs @@ -31,34 +31,9 @@ fn main() { let mut root_folders:Vec; let mut output_string: String = String::new(); let format_game_first: bool; - //let mut game_list:Vec<_>; - - //print language - extension table - print_lang_extension_table(); - + //ask user how they want the todo list formatted - println!("\n\t---====FORMATS====---\ngame first:\n\tGame\n\t\tLanguage ✅/⬜️\n\nlang first:\n\tLanguage\n\t\tGame ✅/⬜️\n\nmake todo list using the game first format?"); - let mut raw_input = String::new(); - io::stdin().read_line(&mut raw_input).expect("Failed to read input"); - //parse raw input - raw_input = raw_input.as_str().to_ascii_lowercase().to_string(); - match &raw_input[0..1] { - "y" => format_game_first = true, - _ => format_game_first = false, - } - - //prompt user to input the file extensions of the languages they want the todo-lists for printed to console - /* - println!("\na todo list with all the languages will be put into todo-list.md"); - println!("enter the file extensions from the table above for the languages you want a todo-list printed to standard output"); - println!("File extensions: (separated by spaces)"); - //parse input for valid languages, store them in langs_to_print - let raw_input = raw_input.as_str().trim().chars().filter(|c| c.is_ascii_alphabetic() || c.is_whitespace()).collect::();//filter out everything but ascii letters and spaces - langs_to_print = raw_input.split(' ')//create an iterator with all the words - .filter(|s| LANGUAGES.iter().any(|tup| tup.1.eq_ignore_ascii_case(*s))) //filter out words that aren't valid extensions (in languages) - .collect(); //collect words into vector - println!("\nwill print: {:?}", langs_to_print); - */ + format_game_first = get_yn_from_user("\n\t---====FORMATS====---\ngame first:\n\tGame\n\t\tLanguage ✅/⬜️\n\nlang first:\n\tLanguage\n\t\tGame ✅/⬜️\n\nmake todo list using the game first format? (y/n)"); //get all folders in ROOT_DIR root_folders = Vec::new(); @@ -91,15 +66,16 @@ fn main() { } }).collect(); + //create todo list if format_game_first { //being forming output string // for every game // every language + ✅/⬜️ for g in root_folders.into_iter() { - let game = g.clone(); + let game = g.clone().into_os_string().into_string().unwrap().chars().filter(|c| !(*c=='.' || *c=='/')).collect::();//get the game name output_string += format!( "### {}\n\n{}\n", //message format - g.into_os_string().into_string().unwrap().chars().filter(|c| !(*c=='.' || *c=='/')).collect::(),//get the game name + game, { let mut s:String = String::new(); //every language + ✅/⬜️ @@ -107,7 +83,7 @@ fn main() { s+="- "; s += lang.0; // + ✅/⬜️ - let paths:Vec<_> = list_files(&game).into_iter().map(|path| path.into_os_string().into_string().unwrap()).collect(); + let paths:Vec<_> = list_files(&g).into_iter().map(|path| path.into_os_string().into_string().unwrap()).collect(); let paths:Vec = paths.into_iter().filter_map(|s| { match Path::new(s.as_str()).extension().and_then(OsStr::to_str) { None => None, @@ -124,8 +100,26 @@ fn main() { } ).as_str(); } + //print the whole list + println!("\n\n{}", output_string); } else { + //figure out what langauges the user wants printed + + //print language - extension table + println!("\n\t---====LANGUAGES TO PRINT====---\na complete todo list will be output to todo-list.md\n"); + print_lang_extension_table(); + + //prompt user to input the file extensions of the languages they want the todo-lists for printed to console + //parse input for valid languages, store them in langs_to_print + let langs_to_print = get_str_from_user("\nenter the file extensions, from the table above,\nfor the languages you want printed to standard output\nFile extensions: (separated by spaces)") + .chars().filter(|c| c.is_ascii_alphabetic() || c.is_whitespace()).collect::();//filter out everything but ascii letters and spaces + let langs_to_print: Vec<_> = langs_to_print.split(' ')//create an iterator with all the words + .filter(|s| LANGUAGES.iter().any(|tup| tup.1.eq_ignore_ascii_case(*s))) //filter out words that aren't valid extensions (in languages) + .collect(); //collect words into vector + println!("\nwill print: {:#?}\n\n", langs_to_print); + + //being forming output string // for every language // every game + ✅/⬜️ @@ -158,13 +152,17 @@ fn main() { s += "\n"; } + //print desired languages only + if langs_to_print.contains(&lang.1) { + print!("### {}\n\n{}",lang.0,s); + } s } ).as_str(); } } - //print output, and write output to file - println!("\n\n{}", output_string); + + //write output to file fs::write(OUTPUT_PATH, output_string).expect("failed to write todo list"); } @@ -182,6 +180,33 @@ fn print_lang_extension_table() { } } +/** + * gets a string from user input + */ +fn get_str_from_user(prompt:&str) -> String { + //DATA + let mut raw_input = String::new(); + + //print prompt + println!("{}",prompt); + + //get input and trim whitespaces + io::stdin().read_line(&mut raw_input).expect("Failed to read input"); + + //return raw input + return raw_input.trim().to_string(); +} +/** + * gets a boolean from user + */ +fn get_yn_from_user(prompt:&str) -> bool { + //get and parse input + match &get_str_from_user(prompt)[0..1] { //get first character + "y" | "Y" => return true, + _ => return false, + } +} + /** * returns a vector containing paths to all files in path and subdirectories of path */ From 93fdf644aa1d042c0f09a36592f77e1e2929d2c6 Mon Sep 17 00:00:00 2001 From: AnthonyMichaelTDM <68485672+AnthonyMichaelTDM@users.noreply.github.com> Date: Wed, 9 Mar 2022 13:22:34 -0800 Subject: [PATCH 2/3] added welcome message --- 00_Utilities/mardown_todo_rust/src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/00_Utilities/mardown_todo_rust/src/main.rs b/00_Utilities/mardown_todo_rust/src/main.rs index 9b461d24..005368df 100644 --- a/00_Utilities/mardown_todo_rust/src/main.rs +++ b/00_Utilities/mardown_todo_rust/src/main.rs @@ -31,6 +31,15 @@ fn main() { let mut root_folders:Vec; let mut output_string: String = String::new(); let format_game_first: bool; + + //print welcome message + println!(" + Markdown TODO list maker + by Anthony Rubick for the basic-computer-games repo + + + "); + //ask user how they want the todo list formatted format_game_first = get_yn_from_user("\n\t---====FORMATS====---\ngame first:\n\tGame\n\t\tLanguage ✅/⬜️\n\nlang first:\n\tLanguage\n\t\tGame ✅/⬜️\n\nmake todo list using the game first format? (y/n)"); From 6ba0a2d7e205a104f36cf447c0b18f5334802ff0 Mon Sep 17 00:00:00 2001 From: AnthonyMichaelTDM <68485672+AnthonyMichaelTDM@users.noreply.github.com> Date: Wed, 9 Mar 2022 13:25:36 -0800 Subject: [PATCH 3/3] bug fix --- 00_Utilities/mardown_todo_rust/src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/00_Utilities/mardown_todo_rust/src/main.rs b/00_Utilities/mardown_todo_rust/src/main.rs index 005368df..12ac5e8e 100644 --- a/00_Utilities/mardown_todo_rust/src/main.rs +++ b/00_Utilities/mardown_todo_rust/src/main.rs @@ -37,12 +37,12 @@ fn main() { Markdown TODO list maker by Anthony Rubick for the basic-computer-games repo - + "); //ask user how they want the todo list formatted - format_game_first = get_yn_from_user("\n\t---====FORMATS====---\ngame first:\n\tGame\n\t\tLanguage ✅/⬜️\n\nlang first:\n\tLanguage\n\t\tGame ✅/⬜️\n\nmake todo list using the game first format? (y/n)"); + format_game_first = get_yn_from_user("\n\t---====FORMATS====---\ngame first:\n\tGame\n\t\tLanguage ✅/⬜️\n\nlang first:\n\tLanguage\n\t\tGame ✅/⬜️\n\nmake todo list using the game first format? (y/n | default No) "); //get all folders in ROOT_DIR root_folders = Vec::new(); @@ -209,8 +209,14 @@ fn get_str_from_user(prompt:&str) -> String { * gets a boolean from user */ fn get_yn_from_user(prompt:&str) -> bool { + //DATA + let input = get_str_from_user(prompt); + + //default in case of error + if input.is_empty() {return false;} + //get and parse input - match &get_str_from_user(prompt)[0..1] { //get first character + match &input[0..1] { //get first character "y" | "Y" => return true, _ => return false, }