mIRC Home    About    Download    Register    News    Help

Print Thread
#17107 27/03/03 08:37 PM
Joined: Jan 2003
Posts: 87
T
Tat Offline OP
Babel fish
OP Offline
Babel fish
T
Joined: Jan 2003
Posts: 87
I am trying to script a quick alias that removes doubled and unneeded color codes out some given text.

Some of the situations such as double bolds double underlines and double reverses are simple to just do a remove on. Double color codes so long as the first color code is blank is also pretty easy.

alias ddc { return $replace($remove($1-,$chr(2) $+ $chr(2)), $chr(3) $+ $chr(3), $chr(3)) }

The problem is I often use quick alias to change the color of specific text and the aliases close the color codes just to have them reopened.

I've tried my hand a bit at picking apart the color codes with regex but it quickly becomes apparent that there are too many combinations to deal with them all very nicely.

B = bold char
/B(\s|[:cntrl:])*B/ replace with B*$regml

Not sure, but has anybody else done something close there to and care to enlighten me on some of the finer points.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
I didn't quite get what you want to do. Could you mention some example inputs and the desired results?


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Dec 2002
Posts: 143
A
Vogon poet
Offline
Vogon poet
A
Joined: Dec 2002
Posts: 143
wouldn't using $strip() do what you are after?

from the help file (/help $strip):

$strip(text,burcmo)
Returns text with all bold, underline, reverse, and color control codes stripped out.

The burcmo parameter is optional, if used, it strips only the specified types of characters.

The m applies the strip settings in the Messages dialog, and the o applies the "only if..." settings in the messages dialog.



Aubs.
cool

Joined: Jan 2003
Posts: 87
T
Tat Offline OP
Babel fish
OP Offline
Babel fish
T
Joined: Jan 2003
Posts: 87
For the example I shall use B to be chr(2) C to be chr(3) ect.

C03B"Welcome to "CBC12B"My channel!"
C03B"Welcome to "C12"My channel!"

I often use alias like
alias e1 { return C03B $+ $1- $+ CB }
alias e2 { return C12B $+ $1- $+ CB }

$e1(Welcome to ) $+ $e2(My channel!)

But this doesn't actually need to do the closing colors if its just going to start them right back up.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Try this:
Code:
alias mcodes {
  var %a
  !.echo -q $regsub($1,/([]|(?:\d\d?(?:\x2C\d\d?)?)?)(?=(?:[]|(?:\d\d?(?:\x2C\d\d?)?)?)*?\1)/g,,%a)
  return %a
}

Fex, //echo -a $mcodes($e1(blah) $+ $e2(bleh))

It works for all control codes (not just Ctrl+K)

Edit: fixed a typo in the regex

Last edited by qwerty; 29/03/03 04:02 AM.

/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Jan 2003
Posts: 87
T
Tat Offline OP
Babel fish
OP Offline
Babel fish
T
Joined: Jan 2003
Posts: 87
Wow.
Thanks. That's some killer code.

For a second I thought the background code was bad, I stand corrected. It just took more figured the end background commas delinated more tokens and didn't like it much in my test. Should work great. Very very nice code...

One bug. BB != B BB = $null

$mcodes(BB"Hello") returns B"Hello" ... when it should just return Hello.

Last edited by Tat; 29/03/03 05:24 AM.
Joined: Jan 2003
Posts: 87
T
Tat Offline OP
Babel fish
OP Offline
Babel fish
T
Joined: Jan 2003
Posts: 87
Also... this next alias should work with a much quicker regsub but I am missing something somewhere... I think the match text () are somehow wrong. Alias should remove double colors to the same colors. Excluding the special case of backgrounds. 256 sets would suck.

alias rdc {
var %i = $regex($1,/00[^]*(00)|01[^]*(01)|02[^]*(02)|03[^]*(03)|04[^]*(04)|05[^]*(05)|06[^]*(06)|07[^]*(07)|08[^]*(08)|09[^]*(09)|10[^]*(10)|11[^]*(11)|12[^]*(12)|13[^]*(13)|14[^]*(14)|15[^]*(15)/g), %rt = $1
while (%i >= 1) {
%rt = $left(%rt, $calc($regml(%i).pos - 1)) $+ $right(%rt, $calc(($regml(%i).pos + 2) * -1))
dec %i
}
return %rt
}


Link Copied to Clipboard