feat(calc): Inform user if qalc is not installed
This commit is contained in:
parent
6cdf2987a9
commit
bb4440e8a3
1 changed files with 65 additions and 50 deletions
|
|
@ -107,13 +107,23 @@ async fn qcalc(regex: &mut Regex, expression: &str, decimal_comma: bool) -> Opti
|
|||
command.args(&["-set", "decimal comma on"]);
|
||||
}
|
||||
|
||||
let mut child = command
|
||||
let spawn = command
|
||||
.env("LANG", "C")
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
.spawn()
|
||||
.ok()?;
|
||||
.spawn();
|
||||
|
||||
let mut child = match spawn {
|
||||
Ok(child) => child,
|
||||
Err(why) => {
|
||||
return Some(if why.kind() == io::ErrorKind::NotFound {
|
||||
String::from("qalc command is not installed")
|
||||
} else {
|
||||
format!("qalc command failed to spawn: {}", why)
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(mut stdin) = child.stdin.take() {
|
||||
let _ = stdin
|
||||
|
|
@ -121,7 +131,15 @@ async fn qcalc(regex: &mut Regex, expression: &str, decimal_comma: bool) -> Opti
|
|||
.await;
|
||||
}
|
||||
|
||||
if let Some(stdout) = child.stdout.take() {
|
||||
let stdout = match child.stdout.take() {
|
||||
Some(stdout) => stdout,
|
||||
None => {
|
||||
return Some(String::from(
|
||||
"qalc lacks stdout pipe: did you get hit by a cosmic ray?",
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let mut reader = smol::io::BufReader::new(stdout).lines().skip(2);
|
||||
let mut output = String::new();
|
||||
|
||||
|
|
@ -179,10 +197,7 @@ async fn qcalc(regex: &mut Regex, expression: &str, decimal_comma: bool) -> Opti
|
|||
};
|
||||
}
|
||||
|
||||
return Some(output);
|
||||
}
|
||||
|
||||
None
|
||||
Some(output)
|
||||
}
|
||||
|
||||
pub async fn uses_decimal_comma() -> bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue