Foreground color replacer

By noMen on Jan 17, 2006

This snippet replaces foreground colors. If you have - for instance - a black background, text with foreground colors black, darkblue and darkbrown are not or hardly readable. You can setup the foreground colors to be replaced in the table at the beginning of the snippet. The given table is suitable for black backgrounds.
In the echo command at the end of the snippet, the nickname is completed with a . for owner, @ for oper and + for voice. The server I'm usually on doesn't support halfops; you have to add that yourself if necessary.
Improvements in v1.1:

  • listens to actions and notices
  • addition of on/off switch in menus
  • simpler setup of color replacement table
    Improvements you can make for yourself:
  • changing echo parameters -tlbfmr
  • sending notices to all channels you are on
  • changing mode char . @ + for nicks
  • setup of variables in an on START event
; Snippet by noMen v1.1 - 2006
; Version 1.0 only listened for on *:TEXT, this version 1.1 also listens to on *:ACTION and on *:NOTICE
; Addition of on/off switch in menus
; Simpler color replacement table, nice suggestion KuTsuM

menu query,status,channel,menubar {
  .-
  .Color Replacer (= $+ $group(#colrep) $+ ): {
    if ($group(#colrep) == off) { .enable #colrep }
    else { .disable #colrep }
    echo -a 4 Color Replacer $group(#colrep)
  }
}

#colrep on

on ^*:TEXT:**:*:{
  if (!$chan) && (!$window($nick)) {
    query $nick
  }
  echo -tlbfmr $iif($chan, $chan $+(<, $iif($nick isowner $chan, ., $iif($nick isop $chan, @, $iif($nick isvoice $chan, +))), $nick, >), $nick $+(<, $nick, >)) $replace($ColRep($1-), $chr(160), )
  haltdef
}

on ^*:ACTION:**:*:{
  if (!$chan) && (!$window($nick)) {
    query $nick
  }
  echo -tlbfmr $iif($chan, $chan $+(*, $chr(32), $iif($nick isowner $chan, ., $iif($nick isop $chan, @, $iif($nick isvoice $chan, +))), $nick), $nick $+(*, $chr(32), $nick)) $replace($ColRep($1-), $chr(160), )
  haltdef
}

on ^*:NOTICE:**:*:{
  echo -tlbfmr $active $iif($chan, $+(-, $iif($nick isowner $chan, ., $iif($nick isop $chan, @, $iif($nick isvoice $chan, +))), $nick, :, $chan, -), $+(-, $nick, -)) $replace($ColRep($1-), $chr(160), )
  haltdef
}

#colrep end

alias ColRep {
  ; setup foreground color replacement table
  ; the values given below are usefull for black backgrounds, for instance: 
  ; - black foreground (01) will be replaced with white (00)
  ; - dark blue foreground (02) will be replaced with dark cyan (10)
  ; - dark brown foreground (05) will be replaced with yellow (08)

  ; replace back: 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
  var %colrep.k = 00 00 10 03 04 08 13 07 08 09 10 11 11 13 14 15

  var %colrep.s = $1-

  var %colrep.r = \03(\d)(?!\d)

  while ($regex(%colrep.s, %colrep.r)) {
    ; as long as there are single digit color codes in the input text, insert a zero
    var %colrep.q = $regsub(%colrep.s, %colrep.r, 0 $+ [ $regml(1) ], %colrep.s)
  }

  ; now find and replace valid foreground colors according to the following scheme (like mIRC does):
  ; FORE     BACK     REPLACE
  ; valid    none     yes
  ; valid    valid    no
  ; valid    invalid  yes
  ; invalid  n,v,i    no

  var %colrep.r = \03(\d{2})(?!,(0|1[0-5]|[1-9]\D))

  while ($regex(%colrep.s, %colrep.r)) {
    ; lookup found foreground color codes in the replacement table and replace them with another one
    ; if no valid foreground color is found, the color code will remain unchanged
    ; also replace  with $chr(160) to prevent the regex to loop eternally
    var %colrep.q = $regsub(%colrep.s, %colrep.r, $chr(160) $+ $iif($regml(1) < 16, $gettok(%colrep.k, $calc($regml(1) + 1), 32), $regml(1)), %colrep.s)
  }

  return %colrep.s
}

Comments

Sign in to comment.
RusselB   -  Nov 30, 2008

This script did not work for me at all.
There was only an on/off option in the menu system.
Nothing in the way of a configuration dialog or method of changing what it was supposed to replace with what I wanted it replaced with.

 Respond  
Bouncer   -  Apr 16, 2007

Remotes.

 Respond  
Baldisar   -  Apr 28, 2006

ok those of us that are unsure about how to code here need to ask one simple question that we kick outselves when we hear the answer usually. Does this go into remotes, aliases, or where?

 Respond  
noMen   -  Jan 19, 2006

I am confused. At Jan 18 5:11 pm you said: \"...problem solved.\" Now you say: \"It does\". What does what? I\'m not sure whether you understand the problem I\'m trying to solve and whether you think QuickStep is right or not. Anyhow, about your question on the while loops I use. Strange enough I can do without the loop for the first $regsub (I understand why), but not for the second. Backreferencing with \1 in the second $regsub doesn\'t work. I\'m not sure were it goes wrong: in the $iif, in the $gettok and/or in the $calc. I need two $regsubs, because I can\'t get the second one working for both single-digit and two-digit foreground colors. Also, you replaced (?!\d) with \D. But these are not the same. With \D the first non-digit will be backreferenced which results in coloring the first non-digit too. Anyhow, thanks for the tip to improve the first $regsub. Can you think of a way how to use \1 in the second one, or even better, to combine the two $regsubs into one?

 Respond  
Yoinx   -  Jan 19, 2006

It does. I was just trying to explain what quickstep was trying to tell you since you guys werent on the same wavelength. IT will change all text of a color. I just got tired of watching the post argument. The only time this fix would work, is if you had a black image as the background or whatever.

Like I said, I was just trying to explian what he was saying.

My issue with this, is why are you using regsub in a while loop with regex.

.echo -q $regsub($1-,/\x03(\d)\D/g,\x03 $+ 0 $+ \1,%text)
%text should have all the colors fixed to be prefixed with a 0. (I believe, Im still pretty new with regex). If that isnt right, it should be somewhat close. Even though they way you have it, and the way I just put it there, wont take into account say, if the background color is a single digit.

 Respond  
noMen   -  Jan 19, 2006

@Yoinx I really like you trying to help me out, because if there is a way to avoid using my snippet I will do it. Unfortunately, I can\'t get it right the way you say. Can I ask you to perform a test, without my snippet having loaded? 1: Make a new colorscheme, change \"normal text\" to white and \"background\" to black. 2: Enter a channel with your normal nick and again with a clone. 3: Type in the window of your clone control-k 1 test ( []1test ) and look in your other window what you can read: nothing I guess unless you drag your mousepointer over the textline. 4: Now try to make it readable as you told me, with right-clicking the color index, while keeping the black background. So far as I can see, if you change the appearance of black, ALL black colored items will change, including the background and the text remains unreadable...... at least in my mIRC.

 Respond  
Yoinx   -  Jan 18, 2006

no.

at the bottom of the colors dialog, you have the color index. if you right-click on white which is normally control+k0 and change it to a new color, anything sent with control+k0 is that new color. their color settings have nothing to do with yours.

you can do the same thing with say.

/color 0 1993170
which turns white into a nice shade of crap. However, mirc doesnt seem to support proper RGB colors, so you have to use $rgb(x,x,x) to get the mirc version of the rgb color code.

But again. These will replace whatever is sent using the color control code, with that color.

/color -r 0
will reset it to white.

 Respond  
noMen   -  Jan 18, 2006

OMG If I have a black background and I set my foreground color to white, I can read everything except when somebody types []1text.... HIS or HER colorcode black overrules MY colorsettings, I\'ll see black on black .......... or do you strip all colorcodes? That is a solution too yeah, but I like to see other peoples colors ... and to read everything they type.

 Respond  
Yoinx   -  Jan 18, 2006

nomen, what he means. If you change the color in there. it doesnt matter. Say, you have a black background. so change color 1 to white. problem solved.

 Respond  
QuickStep   -  Jan 18, 2006

I obviously meant alt+k, which count for all colors

 Respond  
noMen   -  Jan 18, 2006

@Quickstep: you said: ctrl+k, rightclick on one of the twelve colors, you can change the colors. Yeah! That counts for your own text! This snippet changes other people\'s textcolors if they are unreadable.

 Respond  
QuickStep   -  Jan 18, 2006

ALSO:
/color [-lrs]
Allows you to change the color settings for items in the Colors dialog.

The -l switch reloads the color settings from the mirc.ini file.

The -r switch resets the Nth color in the 16 color palette to its default RGB value, with /color -r . To change the color of the Nth color in the 16 color palette to a new value, you can use /color

To change the color of a text item in the color dialog, you can specify the name of the item, eg. Normal text, along with a new palette index.

The -s switch changes the active scheme, with /color -s

 Respond  
QuickStep   -  Jan 18, 2006

ctrl+k, rightclick on one of the twelve colors, you can change the colors

 Respond  
noMen   -  Jan 18, 2006

UNLESS somebody overrules the default textcolor by using a foreground color equal to your background color, that\'s were this snippet can help. Or ... I don\'t understand you correctly, tell me which mIRC option you had in mind....

 Respond  
QuickStep   -  Jan 18, 2006

I can still see the text if I change the default color of 1 to another color, exactly the same like your snippet does, which is build into mirc.

 Respond  
noMen   -  Jan 17, 2006

Nice suggestion KuTsuM. I thought using vars in this way was easier to set up the color replacement table for different background colors, but I see another simple solution now.

 Respond  
KuTsuM   -  Jan 17, 2006

First, why so many /var commands. Second why so many vars? You could place them all into one var and retreive it using tokens

 Respond  
noMen   -  Jan 17, 2006

Yes I agree that mIRC contains that feature BUT if you have a black background and lets say normal text in white and somebody uses foreground color black in his text, you will see nothing. Try this line of text on a black background without and with the color replacer installed:
1This is unreadable on a black background, 2 and this is difficult to read
By the way, I have to update the snippet for on ACTION and on NOTICE, I forgot about it :S

 Respond  
QuickStep   -  Jan 17, 2006

nice code, BUT mirc already has a build in feature to change the default colors. I know this snippet only replaces the colors others type in a channel, but still.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.