mirror of
https://github.com/tiffany352/rink-rs
synced 2024-09-20 22:21:57 +00:00
Show base units in definition listings
This commit is contained in:
parent
888313e7e2
commit
f4ba7f4884
1 changed files with 17 additions and 1 deletions
18
src/eval.rs
18
src/eval.rs
|
@ -559,7 +559,23 @@ impl Context {
|
|||
}
|
||||
let ref def = self.definitions[name];
|
||||
let res = self.lookup(name).unwrap();
|
||||
Ok(format!("Definition: {} = {} = {}", name, def, res.show(self)))
|
||||
let raw = res.show_number_part();
|
||||
let unit = res.unit_name(self);
|
||||
let base_units = Number::unit_to_string(&res.1);
|
||||
let base_units = if unit == base_units { None } else { Some(base_units) };
|
||||
let alias = self.aliases.get(&res.1);
|
||||
let unit = if unit.len() > 0 {
|
||||
format!(" {}", unit)
|
||||
} else {
|
||||
unit
|
||||
};
|
||||
let parens = match (alias, base_units) {
|
||||
(Some(alias), Some(base)) => format!(" ({}; {})", alias, base),
|
||||
(Some(alias), None) => format!(" ({})", alias),
|
||||
(None, Some(base)) => format!(" ({})", base),
|
||||
(None, None) => format!(""),
|
||||
};
|
||||
Ok(format!("Definition: {} = {} = {}{}{}", name, def, raw, unit, parens))
|
||||
},
|
||||
Query::Convert(ref top, Conversion::Expr(ref bottom)) => match (self.eval(top), self.eval(bottom), self.eval_unit_name(bottom)) {
|
||||
(Ok(top), Ok(bottom), Ok(bottom_name)) => {
|
||||
|
|
Loading…
Reference in a new issue