mIRC Homepage
Posted By: Thray Wrapping Colors - 07/10/03 09:52 PM
I made a sockbuf alias that sends text out in lines so that no single line will exceed a certain number of characters.. but of course color doesn't carry over.

I am trying to find a way to make the color carry over to each line, but I can't think of a way to do this despite looking in the help file for a while now.
Is there a way to check a variable for the presence of $chr(3) (the color code character), then get the LAST occurence of it in the string, plus up to 2 numbers that come after it?

alias sockbuf {
  var %buf = $null, %string = $2-, %num = 0
  while (%string) {
    %buf = $gettok(%string,1,32)
    %string = $deltok(%string,1,32)
    if (%num != 0) { %buf =  $+ $chr(32) $+  $+ %buf }
    while ($len(%buf) < 75 && %string) {
      %buf = %buf $gettok(%string,1,32)
      %string = $deltok(%string,1,32)
    if ($len(%buf) > 75) { %string = $instok(%string,$gettok(%buf,$numtok(%buf,32),32),1,32) | %buf = $deltok(%buf,$numtok(%buf,32),32) | sockwrite -n $1 %buf }
    else { sockwrite -n $1 %buf }
    inc %num
Posted By: starbucks_mafia Re: Wrapping Colors - 07/10/03 10:46 PM
I could swear there was an identifier for this already, but I couldn't think of it so try this instead:

get_last_col {
  ;Usage: $get_last_col(<text>)
  ; returns colour last colour codes contained in string (minus colour control code itself)
  ; .pos property returns position of first number
  ; .lpos property returns position of last number
  var %re = /(\d{1,2}(?:,\d{1,2})*)(?:[^]*)$/
  !.echo -q $regex(get_last,$$1,%re)
  if ($prop == pos) return $iif($regml(get_last,1).pos,$ifmatch,0)
  elseif ($prop == lpos) return $iif($regml(get_last,1).pos,$calc($ifmatch + $len($regml(get_last,1)) - 1),0)
  return $iif($regml(get_last,1),$ifmatch,$null)

It works with background colours aswell, so text 04,03blah will return 04,03.

Edit: Forgot to add .lpos property
Edit: Fixed .lpos property (I'll get this alias right sooner or later blush)
© mIRC Discussion Forums