$colortext identifier

By tv3636 on May 12, 2009

$colortext(Color list,text,bur)

-Color list is a list of color codes separated by spaces such as those used in the example aliases below, rainbow and colorize.
-Text is the text to be modified (shockingly)
-bur are optional parameters for bold, underline, and reverse text

**Note that if you want to use color codes with commas you must first set them as a variable and pass the variable as the 1st parameter rather than the numbers themselves.

Thanks to Kirby and jonesy44 for the explode alias!

  • Not too sure how optimal this code is but it's pretty fast so I think it's good enough. If you have any coding suggestions (or compliments :p) please let me know! I'm always looking to improve my coding.

I tested these pretty extensively but if you find a bug please let me know.

Two example aliases are included for use with the identifier as well, enjoy!

/*
$colortext(Color list,text,bur) by tv3636

-Color list is a list of color codes separated by spaces such as those used in the example aliases below, rainbow and colorize.
-Text is the text to be modified (shockingly)
-bur are optional parameters for bold, underline, and reverse text

**Note that if you want to use color codes with commas you must first set them as a variable and pass the variable as the 1st parameter rather than the numbers themselves.

Thanks to Kirby and jonesy44 for the explode alias!
*/

alias colortext {
  var %y = 1
  var %cols = $1
  var %colscount = $r(1,10)
  while (%y <= $numtok($2,32)) {
    var %text = $explode($gettok($2,%y,32),32)
    var %x = 1
    while (%x <= $numtok(%text,32)) {
      var %out = %out $+  $+ $gettok(%cols,%colscount,32) $+ $gettok(%text,%x,32) $+ 
      inc %colscount | inc %x
      if (%colscount > $numtok($1,32)) %colscount = 1
    }
    %out = %out $+ $chr(160) 
    inc %y
  }
  return $replace($3,b,,u,,r,) $+ $left(%out,-1)
}

alias explode { var %x $2 | return $regsubex($1,/(.)/g,$+(\1,$chr(%x))) }

;Example aliases using $colortext()

alias rainbow { msg $active $colortext(04 13 06 12 10 11 09 08 07 05,$1-,b) }

alias colorize { var %cols = 04,06 07,04 08,07 09,08 12,09 13,12 06,13 04,06 07,04 08,07 09,08 12,09 13,12 06,13 | msg $active $colortext(%cols,$1-,b) }

Comments

Sign in to comment.
tv3636   -  May 12, 2009

:/ Well as I said I don't know any regex. I guess this is pretty useless and way too long then. Oh well. The one thing that doesn't do is keep an order of the colors so that it looks nicer and avoids colors that are unwanted (although I'm sure there's some regex magic that could accomplish that in like 4 characters)

 Respond  
WorldDMT   -  May 12, 2009

hi
sorry i don't speak verry well english

why all that code for mixed color of line text??

u can only do that

alias colortext return $replace($2,b,,u,,r,) $+ $regsubex($1,/()/g,$chr(3) $+ $r(1,15) $+ \1)

for test use

//echo -a $colortext(just for test,bur)

or

alias testcolor echo -a $colortext($1-,bur)

/testcolor just for test

 Respond  
Kirby   -  May 12, 2009

Yeah, I've seen his $explode before, but haven't commented on it. :P

But I'm not sure why for the alias I just posted, I have to /var %x, and not use $2 directly in $chr. =/

 Respond  
tv3636   -  May 12, 2009

Alright, sounds good. I don't know anything about regex haha. And that alias was posted by jonesy44 by the way.
http://www.hawkee.com/snippet/6008/

 Respond  
Kirby   -  May 12, 2009
alias explode {
  var %x = 1
  while (%x <= $len($1)) { var %explode = %explode $+($mid($1,%x,1),$chr($gettok($1-,$0,32))) | inc %x }
  return %explode
}

can also be:

alias explode { var %x $2 | return $regsubex($1,/(.)/g,$+(\1,$chr(%x))) }
 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.