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"