mIRC Home    About    Download    Register    News    Help

Print Thread
$colorat() or generalized $controlat() #237738 30/05/12 06:16 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline OP
Hoopy frood
OP Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
It would be useful in some situations to be able to have mIRC calculate the "effective colour" (or control codes) at a given position in a line. Consider the text (control codes replaced with ^K, ^B, ^U, etc.):

^K1,4hello ^K12 world ^K

If someone wanted to programmatically copy part of the line using /clipboard, say, the word "world", it would be non-trivial to copy the text along with its colours in the buffer. Note the effective colour at the "w" is ^K12,4.

It would be nice to have an identifier that returned the effective control code(s) to reproduce text at a given point in a line, for example:

Code:
//echo -a $colorat(^K1,4hello ^K12 world ^K, 15)


Would return ^K12,4.

The generalized version of this would be a $controlat identifier, perhaps better suited, where you could specify all codes you want mIRC to calculate:

Code:
//echo -a $controlat(^K1,4hel^Ulo ^B^K12^Bworld ^K, 17, bku)


Would return ^U^K12,4.

Perhaps a way to grab a range of text (like $mid but with control codes copied) would also be a good solution here. In this case, mIRC could perform proper wrapping of the codes:

Code:
//echo -a $midc(^K1,4hel^Ulo ^B^K12^Bworld ^K, 17, 2, bku)


Would return ^U^K12,4wo^K^U, so that it could be safely(*) used in a line. The downside of this is that occasionally the scripter only wants the control code data and not the text, but perhaps N=0 could return just the control codes.

(*) not entirely "safe", since mIRC would need to know the destination line to properly end a colour code, but at least you would not end up with leaking codes. Doing this manually with something like the initially suggested $controlat would require the scripter to check for each code and manually add the end-code, though there may be some obscure tricks to do this easily.

Although this is scriptable, doing the effective calculation is non-trivial, and, if mIRC ever adds colours or control codes, each script would need updating. Having a builtin identifier for this gives out of the box support and makes sure the parsing rules stay in sync with how mIRC actually interprets data on screen.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: $colorat() or generalized $controlat() [Re: argv0] #237740 30/05/12 11:31 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
I like this idea. I've had to calculate the codes before and it's definitely challenging. And even though I've managed it in most cases, there are still cases where I haven't been able to correctly determine the color at a given point in the line. And even where I could, it required a lot of work. It would be great to have something built in that would do it easily.


Invision Support
#Invision on irc.irchighway.net
Re: $colorat() or generalized $controlat() [Re: Riamus2] #237741 31/05/12 01:51 AM
Joined: Nov 2009
Posts: 295
P
pball Offline
Fjord artisan
Offline
Fjord artisan
P
Joined: Nov 2009
Posts: 295
I'll third this. Made a script which replaces stuff in a line and it wasn't fun to get the color codes so the rest of the line appeared as it was.


http://scripting.pball.win
My personal site with some scripts I've released.
Re: $colorat() or generalized $controlat() [Re: argv0] #237757 01/06/12 03:24 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
+1, something like this would be very useful.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: $colorat() or generalized $controlat() [Re: argv0] #237798 03/06/12 11:23 PM
Joined: Jul 2006
Posts: 3,576
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,576
Good idea. Here is a scripted version for the meantime:
Code:
alias colorat {
  if ($prop == set) {
    if ($1 != $chr(15)) {
      var %i $iif($2,$2,$gettok(%colorat,2,44))
      %colorat = $1 $+ $iif($1,$iif(%i,$chr(44) $+ %i))
    }
    else %colorat =
  }
  else {
    set -u %colorat
    var %r /(?:\x03(?:(\d+)(?:,(\d+))?)?|(\x0F))/g,%r $regsubex($left($1,$2),%r,$colorat(\1,\2).set)
    %r = %colorat
    unset %colorat
    return $iif(%r != $null,$chr(3) $+ %r)
  }
}

alias controlat {
  if ($prop == set) {
    if ($1 != $chr(15)) {
      if ($1 isin %controlat) %controlat = $remove(%controlat,$1)
      else %controlat = %controlat $+ $1
    }
    else %controlat =
  }
  else {
    set -u %controlat
    var %c $iif($3,$3,kubir),%r $+(/,$chr(40),$left($regsubex($remove(%c,k),/(.)/g,\x $+ $base($replace(\1,u,31,b,2,i,29,r,22),10,16,2) $+ |),-1),|\x0F,$chr(41),/g),%r $regsubex($left($1,$2),%r,$controlat(\1).set)
    %r = %controlat
    unset %controlat
    return %r $+ $iif(k isin %c,$colorat($1,$2))
  }
}
alias midc returnex $controlat($1,$2,$4) $+ $mid($1,$2,$3)


Last edited by Wims; 04/06/12 03:42 AM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $colorat() or generalized $controlat() [Re: Wims] #237799 03/06/12 11:57 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Unfortunately, this doesn't handle Ctrl-O in the text when determining the color and it counts the codes when determining where you are in the line (that second part may or may not be an issue depending on exactly what you're using this for). But it's a good start.


Invision Support
#Invision on irc.irchighway.net
Re: $colorat() or generalized $controlat() [Re: Riamus2] #237800 04/06/12 12:01 AM
Joined: Jul 2006
Posts: 3,576
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,576
I completely forgot about ctrl+o!! I'll fix it eventually frown

Edit: should be ok now

Last edited by Wims; 04/06/12 01:18 AM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net