|
Joined: Oct 2003
Posts: 3,918
Hoopy frood
|
OP
Hoopy frood
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: //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: //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: //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"
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
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
|
|
|
|
Joined: Nov 2009
Posts: 295
Fjord artisan
|
Fjord artisan
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.
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
+1, something like this would be very useful.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Jul 2006
Posts: 4,213
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,213 |
Good idea. Here is a scripted version for the meantime: 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.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
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
|
|
|
|
Joined: Jul 2006
Posts: 4,213
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,213 |
I completely forgot about ctrl+o!! I'll fix it eventually Edit: should be ok now
Last edited by Wims; 04/06/12 01:18 AM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
|