Improved `var` command

pull/2/head
Mark 2023-08-04 22:40:09 -07:00
parent 36d041c3c1
commit 5093015dd2
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 17 additions and 18 deletions

View File

@ -148,15 +148,22 @@ pub fn do_command(
let mut t = FormattedText::new("".to_string()); let mut t = FormattedText::new("".to_string());
if v.len() != 0 {
t.push("\n╞═══ [t]User-Defined Variables[n] ═══╡\n");
let mut longest = 0; let mut longest = 0;
for (key, _) in v { for (key, _) in v {
if key.len() > longest { if key.len() > longest {
longest = key.len(); longest = key.len();
} }
} }
for (key, (args, _exp)) in f {
let s = format!("{key}({})", args.join(", "));
if s.len() > longest {
longest = s.len();
}
}
if v.len() != 0 {
t.push("\n╞═══ [t]User-Defined Variables[n] ═══╡\n");
for (key, value) in v { for (key, value) in v {
let padding = " ".repeat(longest - key.len()); let padding = " ".repeat(longest - key.len());
@ -171,20 +178,12 @@ pub fn do_command(
if f.len() != 0 { if f.len() != 0 {
t.push("\n╞═══ [t]User-Defined Functions[n] ═══╡\n"); t.push("\n╞═══ [t]User-Defined Functions[n] ═══╡\n");
let mut longest = 0;
for (key, (args, _exp)) in f {
let s = format!("{key}({})", args.join(", "));
if s.len() > longest {
longest = s.len();
}
}
for (key, (args, exp)) in f { for (key, (args, exp)) in f {
let padding = " ".repeat(longest - key.len()); let s = format!("{key}({})", args.join(", "));
let padding = " ".repeat(longest - s.len());
t.push(&format!( t.push(&format!(
" {key}({}){padding} = [c]{v}[n]\n", " {s}{padding} = [c]{v}[n]\n",
args.join(", "),
v = exp.to_string(), v = exp.to_string(),
)); ));
} }