Print entries that are just a wikipedia entry.

This commit is contained in:
Hiers 2024-02-28 20:34:31 +00:00
parent 8813605e5f
commit d9fabf6570
4 changed files with 102 additions and 213 deletions

View file

@ -103,7 +103,7 @@ fn main() -> Result<(), ureq::Error> {
}
} else { /* Word search */
/* Do API request */
let body: Value = ureq::get(&format!(JISHO_URL!(), query))
.call()?

View file

@ -79,15 +79,17 @@ fn print_item(query: &str, value: &Value, output: &mut String) -> Option<usize>
}
fn format_form(query: &str, form: &Value, output: &mut String) -> Option<()> {
let reading = form
.get("reading")
.map(value_to_str)
.unwrap_or(query);
if let Some(reading) = form.get("reading") {
let word = value_to_str(form.get("word").unwrap_or(form.get("reading")?));
let word = value_to_str(form.get("word").unwrap_or(reading));
write!(output, "{}", format_args!("{}[{}]", word, value_to_str(reading))).ok()?;
} else if let Some(word) = form.get("word") {
write!(output, "{}", format_args!("{}", value_to_str(word))).ok()?;
} else {
write!(output, "{}", format_args!("{}",query)).ok()?;
}
write!(output, "{}", format_args!("{}[{}]", word, reading)).ok()?;
Some(())
}
@ -134,7 +136,7 @@ fn format_sense(value: &Value, index: usize, output: &mut String, prev_parts_of_
let t = format_sense_tags(value, output);
format_sense_info(value, output, t);
output.push('\n');
return is_part_of_speech_new;
}