cecho's insertText flag

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

cecho's insertText flag

Post by tsuujin »

I'm trying to use cecho to reprint a trigger'd word as something else colored using replace. I know I can get this to work with insertText by using selectString to get the column number of the matched word and getLineCount() to get the line number of the match, then using a blank replace (replace("")) to clear the text, move the cursor and reprint with insertText.

however, this doesn't seem to work with cecho. According to the documentation, the third argument to cecho tells cecho to use insertText rather than echo for the printing, but it doesn't seem to register. Even with that argument flipped to true (or false, i tried both) it still prints to the end of the line no matter where you have the cursor currently.

Can we get a fix for this, or at least a check on it, please?

here's the code I'm using:

Code: [show] | [select all] lua
function creplace(orig,new)
	local i = selectString(orig,1)
	replace("")
	moveCursor("main",i,getLineCount())
	cecho(new,nil,nil,true)
end
creplace(matches[1],"<red>testing!!")

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: cecho's insertText flag

Post by Denarii »

Use cinsertText(window, text) (window is optional).

The documentation is out of date.

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

Re: cecho's insertText flag

Post by tsuujin »

Excellent. Thank you!

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

Re: cecho's insertText flag

Post by tsuujin »

.....

Can we get a one-up on this with a native creplace?

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: cecho's insertText flag

Post by Vadi »

Yeah I'd love it. Always bothered me that we didn't have anything for replace.

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

Re: cecho's insertText flag

Post by tsuujin »

Ok, here's a really, really odd bug.
Code: [show] | [select all] lua
function creplace(orig,new)
    local i = selectString(orig,1)
    replace("")
    moveCursor(i,getLineCount())
    cinsertText(new)
    resetFormat()
end
This is what I'm using now for a colored replace. In general, it works fine.

However, this:
Code: [show] | [select all] lua
creplace(matches[1],"<red>((<coral>INFILTRATE<red>)) ")
produces this:
huh.png
huh.png (6.43 KiB) Viewed 5585 times

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: cecho's insertText flag

Post by Denarii »

Okay. Basically, the cecho/cinsertText functions split the string based on the color tags and then loop through setting colors and echoing. So when you've manually positioned the cursor, it inserts each section of the text at that point, rather than in order. So it's inserting a red ((, then coral INFILTRATE at the same point, pushing the (( to the end, then the red )) at that same point. So you end up with )) INFILTRATE((. Right now cinsertText uses the same logic as cecho, just with insertText used instead of echo. I'm going to need to make some changes to the insertText functions to move the cursor as it's inserting.

frasten
Posts: 1
Joined: Tue Jul 12, 2011 11:00 am

Re: cecho's insertText flag

Post by frasten »

I don't know if it breaks anything, but I tried to fix this issue in cinsertText(), and it works for me.
Patch: https://gist.github.com/1077846

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: cecho's insertText flag

Post by Vadi »

The fix indeed seems to work, thanks! I added it to https://github.com/Beliaar/mudlet-lua which'll make it's way into Mudlet when Heiko syncs next.

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: cecho's insertText flag

Post by Denarii »

I had finally gotten around to fixing this today. :/ I'm also trying to add cinsertLink, but insertLink isn't implemented properly. Heiko left out the custom format flag.

Post Reply