diff --git a/README.md b/README.md index 3001c60..5351a9a 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,26 @@ A CLI tool that finds words of a specific length with letters in a specific loca I use this for building crosswords https://github.com/user-attachments/assets/e3393b22-b91d-45f2-ac16-19c11be40fc2 + +## Installation + +### Build from Source + +Clone the repository and build the project using [Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html): + +```sh +git clone https://github.com/Talon-Games/word-finder +cd word-finder +cargo build --release +# The binary will be located at target/release/word-finder +``` + +To add the binary to your PATH, run: + +```sh +cargo install --path . +``` + +### Pre-built Binaries + +Pre-built binaries are available for Windows, macOS, and Linux on the [releases page](https://github.com/Talon-Games/word-finder/releases). diff --git a/src/main.rs b/src/main.rs index cf83c86..0244648 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,18 +45,25 @@ fn search() { println!("--------------------------------------"); } -fn find_words_from_list(word_length: i32, letter_requirements: Vec) -> Vec<&'static str> { +fn find_words_from_list(word_length: i32, letter_requirements: Vec) -> Vec { let words_file: Vec<&str> = include_str!("./words.txt") .lines() .map(|line| line.trim()) - .filter(|line| !line.is_empty() && line.len() == word_length as usize) + .filter(|line| { + !line.is_empty() + && line.split("::").collect::>()[0].trim().len() == word_length as usize + }) .collect(); let mut fitting_words = Vec::new(); - for word in words_file { + for line in words_file { let mut valid = true; + let line: Vec<&str> = line.split("::").collect(); + let word = line[0].trim(); + let mut definition = line[1].trim(); for (i, letter) in word + .trim() .split("") .into_iter() .filter(|s| !s.is_empty()) @@ -73,7 +80,11 @@ fn find_words_from_list(word_length: i32, letter_requirements: Vec) -> V continue; } - fitting_words.push(&*word) + if definition.len() == 0 { + definition = "[no definition]" + } + + fitting_words.push(format!("{} - {}", word, definition)) } fitting_words