Trying to capture lines with only one text colour

Matak
Posts: 9
Joined: Thu Jun 23, 2011 11:41 pm

Trying to capture lines with only one text colour

Post by Matak »

Hi,

After a little help with some scripting to create a trigger.
Ive used some code from one of the tabbed chat packages that looked close to what i wanted.
What id like to do is find lines that contain only a certain fg colour.
So with a color trigger set to the correct fg and bg colors the following picks up any line where the fg color appears.
Unforunately im after lines where only the fg colour appears.
Any help would be appreciated.
Code: [show] | [select all] lua
selectString(line,1)
    do stuff in here

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Trying to capture lines with only one text colour

Post by Rakon »

You can make a multiline trigger match (with the line count 0) in order to capture lines of only a certain colour.

Check the settings in the image below to see what I mean.
Image

Matak
Posts: 9
Joined: Thu Jun 23, 2011 11:41 pm

Re: Trying to capture lines with only one text colour

Post by Matak »

Thanks for the reply.
I guess i didnt word my question well enough.
This is currently what I am doing.
However, what im trying to do extra is only match lines where all text is the foreground colour - not just one character.
As mentioned ive tried using selectString in combination with the above but so far its just not quite right.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Trying to capture lines with only one text colour

Post by Heiko »

There are functions to determine the foreground and background color of every character in the buffer. There is also a function to test for ANSI colors as being used by the MUD. You can set up a color gate trigger that runs your test script only if the line contains your wanted color to make things faster. Then you can iterate over all characters in the current line to find out if they are all the same color.

Trilliana
Posts: 21
Joined: Tue Nov 24, 2009 2:47 am

Re: Trying to capture lines with only one text colour

Post by Trilliana »

try this:
http://forums.mudlet.org/viewtopic.php?f=6&t=1282

I had someone take that and grab people's names on CWHO and turn it into a list and it works really well

Matak
Posts: 9
Joined: Thu Jun 23, 2011 11:41 pm

Re: Trying to capture lines with only one text colour

Post by Matak »

Thanks for the suggestions.
Ive realised that i dont need the whole line checked - only the first character of each line.
What ive come up with is the following. It doesnt quite work as it never echos match but im hoping its not too far wrong.
I guess i dont understand how isAnsiFgColor works or what it actually works on.
test = string.sub(line, 1, 1) does actually pull out the first character from any line that gets hit by the color trigger.
matches[1] does pull out the text that was initially matched.
What i want to do is to check "test" for light green

Note: I have a color trigger set up for light green and this is the code below that.
5 is light green also according to the documentation
Code: [show] | [select all] lua
getCurrentLine()
local test
test = string.sub(line, 1, 1)
echo(test)
	echo(matches[1])
	if isAnsiFgColor(5) then
		echo("MATCH")
	else
		echo("NOMATCH")
end
As always help or pointers are appreciated.

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: Trying to capture lines with only one text colour

Post by Oneymus »

I'm confused; why do you need to test the color of the line via Lua? A Mudlet color trigger does -exactly- that; it will only fire if the foreground color matches whichever color you specify.

Do you have some specific need for the color information in your code?

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Trying to capture lines with only one text colour

Post by tsuujin »

Oneymus wrote:I'm confused; why do you need to test the color of the line via Lua? A Mudlet color trigger does -exactly- that; it will only fire if the foreground color matches whichever color you specify.

Do you have some specific need for the color information in your code?
There are MUDs out there that use color for significance within a variety of lines. Sometimes it's more effective to match for text, then check colors within the script.

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: Trying to capture lines with only one text colour

Post by Oneymus »

tsuujin wrote: There are MUDs out there that use color for significance within a variety of lines. Sometimes it's more effective to match for text, then check colors within the script.
Oh, I get that. I've played, and worked on, MuDs that make liberal use of color. If Matak only needs to check the first letter of the line for its color, however, that would not seem to be the case.
Matak wrote: However, what im trying to do extra is only match lines where all text is the foreground colour - not just one character.
This is exactly what Mudlet color triggers do, is it not? So my confusion stems from the insistence that the color trigger isn't -all- that Matak needs; I'm just curious why this isn't enough. Is there more functionality that is necessary that hasn't been communicated?

Matak
Posts: 9
Joined: Thu Jun 23, 2011 11:41 pm

Re: Trying to capture lines with only one text colour

Post by Matak »

I thought i posted another message but doesnt look like i stuffed up somehow.

OK so what i want is to find the colour of the first character on each line and if it matches a colour in a list i have then process it. Unfortunately there are no text matches that i can do on these lines. Totally random as to what will be coming in.

My problem comes when trying to find the colour of that character.
In using a colour trigger its capturing any line that has the colour in it.
This wont work for me as there are a lot of lines using the same colours. (Not first character though)
When using isAnsiFgColor i dont know if its using the original line match or the character that ive found.
Please note the code below isnt syntactically correct - just trying to describe what im after.
So here is what id like to do

"This is a line from the mud"

Code: [show] | [select all] lua
getCurrentLine()

local firstChar = string.sub(line, 1, 1)

if firstChar blue then --i know isAnsiFgColor(colour) compares a colour but i dont know what its using
  process this
else
  do not process this
end
As always if anyone has some ideas or some code to do this that would be great.

Post Reply