You can still shorten this & get rid of the while loop and the long last line.
Here\'s what I came up:
alias bar {
var %l = 20, %c = $calc($2 / $1), %d = $int($calc(%l * %c)), %p = $calc(%c * 100) $+ %, %ps = $int($calc($len(%p) / 2))
var %bar = $str($chr(160),%l), %p1 = $calc((%l / 2) - %ps), %p2 = $calc((%l / 2) - %ps + $len(%p))
%bar = $mid(%bar,1,%p1) $+ %p $+ $mid(%bar,%p2,$calc(%l - %p2))
return 12,08 $+ $left(%bar,%d) $+ 08,12 $+ $right(%bar,$calc(%l - %d)) $+ $3-
}
Same usage: $bar(C,N,text)