diff --git a/cli/src/reedline.rs b/cli/src/reedline.rs index c5e5b2bf..2ccf1d0d 100644 --- a/cli/src/reedline.rs +++ b/cli/src/reedline.rs @@ -201,15 +201,13 @@ pub fn enter_code() -> eyre::Result { let prompt = CodePrompt::default(); - loop { - let sig = line_editor.read_line(&prompt); - match sig { - Ok(Signal::Success(buffer)) => return Ok(buffer), - // TODO: fix temporary work around - Ok(Signal::CtrlC) => bail!("Ctrl-C received"), - Ok(Signal::CtrlD) => bail!("Ctrl-D received"), - Err(e) => bail!(e), - } + let sig = line_editor.read_line(&prompt); + match sig { + Ok(Signal::Success(buffer)) => return Ok(buffer), + // TODO: fix temporary work around + Ok(Signal::CtrlC) => bail!("Ctrl-C received"), + Ok(Signal::CtrlD) => bail!("Ctrl-D received"), + Err(e) => bail!(e), } } diff --git a/src/core/wordlist.rs b/src/core/wordlist.rs index b29da825..7f35a1a9 100644 --- a/src/core/wordlist.rs +++ b/src/core/wordlist.rs @@ -2,15 +2,9 @@ use rand::{rngs::OsRng, seq::SliceRandom}; use serde_json::{self, Value}; use std::fmt; -/// Represents a collection of word lists used for generating and completing wormhole codes. -/// -/// The `Wordlist` struct contains multiple lists of words and information about -/// how many words should be in a complete wormhole code. #[derive(PartialEq)] pub struct Wordlist { - /// The number of words that should be in a complete wormhole code. pub num_words: usize, - /// A vector of word lists. Each inner vector represents a distinct list of words. pub words: Vec>, } @@ -26,35 +20,6 @@ impl Wordlist { Wordlist { num_words, words } } - /// Returns a list of word completions based on the given prefix. - /// - /// This method generates completions for a partial wormhole code. It takes into account - /// the number of dashes in the prefix to determine which word list to use for completions. - /// - /// # Arguments - /// - /// * `prefix` - A string slice that holds the partial wormhole code to complete. - /// - /// # Returns - /// - /// A vector of Strings containing all possible completions. - /// - /// # Behavior - /// - /// - The method cycles through word lists based on the number of dashes in the prefix. - /// - It completes the last partial word in the prefix. - /// - If the completion isn't for the last word in the code, it appends a dash. - /// - The returned completions are sorted alphabetically. - /// - /// # Examples - /// - /// ``` - /// use your_crate_name::WordList; - /// - /// let wordlist = WordList::new(); - /// let completions = wordlist.get_completions("7-ze"); - /// assert!(completions.contains(&"7-zebra-".to_string())); - /// ``` #[allow(dead_code)] // TODO make this API public one day pub fn get_completions(&self, prefix: &str) -> Vec { let count_dashes = prefix.matches('-').count(); @@ -90,30 +55,6 @@ impl Wordlist { completions } - /// Generates a random wormhole code. - /// - /// This method creates a new wormhole code by randomly selecting words from the word lists. - /// It ensures that the generated code has the correct number of words as specified by `num_words`. - /// - /// # Returns - /// - /// A String containing the randomly generated wormhole code, with words separated by dashes. - /// - /// # Behavior - /// - /// - Uses the OS's random number generator for secure randomness. - /// - Cycles through the word lists if `num_words` is greater than the number of available lists. - /// - Joins the selected words with dashes to form the final code. - /// - /// # Examples - /// - /// ``` - /// use your_crate_name::WordList; - /// - /// let wordlist = WordList::new(); - /// let code = wordlist.choose_words(); - /// assert_eq!(code.split('-').count(), wordlist.num_words()); - /// ``` pub fn choose_words(&self) -> String { let mut rng = OsRng; let components: Vec = self