diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-01-22 21:52:55 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-01-22 21:52:55 +0100 |
| commit | d672e1a6593edb7c324bf90111672bf2e1b2449e (patch) | |
| tree | 84e879ee3996757bc1ae3ea1d5b98db3ab235c7a | |
| parent | 3fe7bee3cb87708f08c322a4f71db89012ee680a (diff) | |
| download | mihi-d672e1a6593edb7c324bf90111672bf2e1b2449e.tar.gz mihi-d672e1a6593edb7c324bf90111672bf2e1b2449e.zip | |
words: show relevant flags as well
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
| -rw-r--r-- | crates/cli/src/words.rs | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/crates/cli/src/words.rs b/crates/cli/src/words.rs index 69e0cea..49024ac 100644 --- a/crates/cli/src/words.rs +++ b/crates/cli/src/words.rs @@ -687,17 +687,68 @@ fn humanize_kind(kind: &str) -> &str { } } -fn show_info(word: Word) -> Result<(), String> { - // Title. - match word.gender { - Gender::None => println!("Word: {} ({})", word.enunciated, word.category), - _ => println!( - "Word: {} ({} {})", +fn humanize_flag(s: &String) -> String { + match s.as_str() { + "deponent" => "deponent", + "semideponent" => "semi-deponent", + "onlysingular" => "only singular forms", + "onlyplural" => "only plural forms", + "compsup_prefix" => "comparative and superlative forms require a prefix", + "indeclinable" => "indeclinable", + "irregularsup" => "irregular superlative", + "nopassive" => "no passive forms", + "nosupine" => "no supine form", + "noperfect" => "no perfect forms", + "nogerundive" => "no gerundive", + "impersonal" => "impersonal", + "impersonalpassive" => "impersonal only on its passive forms", + "noimperative" => "no imperative forms", + "noinfinitive" => "no infinitive forms", + "shortimperative" => "irregular short imperative", + "onlythirdpassive" => "only forms on the third person of the passive voice", + "notcomparable" => "not comparable", + "onlyperfect" => "only perfect forms", + "contracted_vocative" => "contracted vocative, as in filī, not filiī*", + _ => "", + } + .to_string() +} + +fn humanize_flags(word: &Word) -> String { + let mut flags = vec![]; + + if let Some(obj) = word.flags.as_object() { + for (key, value) in obj { + if value.as_bool().unwrap_or_default() { + flags.push(humanize_flag(key)); + } + } + } + + flags.join("; ") +} + +fn title_for_word(word: &Word) -> String { + let s = match word.gender { + Gender::None => format!("{} ({}", word.enunciated, word.category), + _ => format!( + "{} ({} {}", word.enunciated, word.gender.abbrev(), word.category ), + }; + + let flags = humanize_flags(word); + if flags.is_empty() { + return format!("{})", s); } + format!("{}; {})", s, flags) +} + +fn show_info(word: Word) -> Result<(), String> { + // Title. + println!("Word: {}", title_for_word(&word)); // Conjugation, declension + kind. // TODO: to_human |
