Progress/Filler Bar - $p.bar

By Jonesy44 on Mar 29, 2009

Usage: $p.bar([N]%|[X]/[C][,<1>,<2>]|[<1>,<2>,<3>,<4>])[.s]
Either N%, where N is a percentage (out of 100)
Or X/C where X is a number out of C

The additional .s prop is to strip any color from the string
Examples:

$p.bar(40%).s

would return > [||||......]

$p.bar(1/2)

would return > [|.] (in color)

Update
You can now add extra paramaters to change the values using the identifier. $p.bar(N,X,-) would return the [X---------]

Or use $p.bar(N,{,X,-,}) and it will return {X---------} etc. :)

Image

alias p.bar {
  ; --------------------
  ; Usage: $p.bar([N]%|[X]/[C])[.s]
  ; Either N%, where N is a percentage (out of 100)
  ; Or X/C where X is a number out of C
  ; --------------------
  ; The additional .s prop is to strip any color from the string
  ; Examples: $p.bar(40%).s would return [||||......]
  ;         : $p.bar(1/2) would return [|.] (in color)
  ; edit paramaters here
  ; -------------------- 
  var %open.char = 0,1[
  var %clos.char = 0,1]
  var %pbar.fill = 4|
  var %pbar.empt = 0,1.
  if ($3) { var %pbar.fill = $2, %pbar.empt = $3 }
  if ($5) { var %open.char = $2, %pbar.fill = $3, %pbar.empt = $4, %clos.char = $5 }
  ; -----------------
  ; stop editing here
  ; -----------------
  if ($regex($1,^\d*/\d*$)) { var %p1 = $gettok($1,1,47)), %p2 = $calc($gettok($1,2,47) - %p1) }
  elseif ($regex($1,^\d*%$)) { var %p1 = $calc($remove($1,%) / 10)), %p2 = $calc(10 - %p1)) }
  if (%p1) {
    var %r = $+(%open.char,$str(%pbar.fill,%p1),$str(%pbar.empt,%p2),%clos.char,$iif($right(%clos.char,-1) != ,))
    return $iif($prop == s,$strip(%r),%r) 
  }
  else { return 2* $!pbar: error }
}

Comments

Sign in to comment.
Jonesy44   -  Aug 16, 2010

Welcome, ES.
This script assumes your values are already correct i suppose :)

 Respond  
Lucius   -  Aug 12, 2010

Nice, not quite as good to look at as one I found trawling the net but the extra options are a great addition.
7/10

note:-
I found one that used pure colour and added the percentage inside the bar but was restricted to $percentbar(total/percent) format EG: $percentbar(1300,487) or $percentbar(100/25)

 Respond  
ES   -  Aug 11, 2010

perfect, thx mate

 Respond  
Jonesy44   -  Mar 30, 2009

Updated, & fixed a little bug in the regex. :)

 Respond  
Jonesy44   -  Mar 30, 2009

Oh yeah.. sure. i will do that in a sec.

 Respond  
Firstmate   -  Mar 29, 2009

I meant, you can make it return it in ^> if you want

e.g. $p.bar(50%,>,^)
returns >>>>>^^^^^

 Respond  
Jonesy44   -  Mar 29, 2009

Go for it, thanks for rating, glad you liked it :)

 Respond  
Tamaki   -  Mar 29, 2009

can you make this usable in a dialog? like in a text?

-edit-

nevermind...i found it ^_^
great script 10/10

and if you don't mind, i wanna put it in my integration script |which still needs a lot of fixing :(

 Respond  
Jonesy44   -  Mar 29, 2009

Then can, Firstmate. Check the top of the script :)

And thank you Kirby, hope you can use it in future :D

 Respond  
Firstmate   -  Mar 29, 2009

You should let the person put in their own character.

 Respond  
Kirby   -  Mar 29, 2009

I think many people can use this for "disk space" scripts or "___ meter" scripts, so it is useful. Thus, this snippet is coded quite well, in my opinion. (I might use this later in future codes. :P)
7.0 from me.

 Respond  
Jonesy44   -  Mar 29, 2009

Thanks bro, care to rate?

just fyi, this was made from scratch.. just incase :P

 Respond  
Kirby   -  Mar 29, 2009

Lol, I made a similar identifier but with yellow stars (for rating, up to 10).

Works well jonesy. :)

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.