Mudlet features and API requests

Widjet
Posts: 30
Joined: Thu Apr 22, 2010 1:43 am

Re: Mudlet API requests

Post by Widjet »

I would like a function to copy rich text from a console into a string - ie: programmatic access to something similar to the copy as HTML function.

The result would be a string with formatting codes in it - HTML perhaps, though I'd actually prefer the raw server text, complete with ANSI colour codes, or perhaps with colours embedded in a format that cecho etc. understand.

copy() and paste() work for transferring between buffers, but if it's not so useful if I want to save something for later, for example saving the output of the MAP command in-game.

Two ways I could implement it at the moment:
  • Have colour triggers for each of the possible colours, and a match-everything trigger. Then find colour matching parts of the full line and tag them appropriately.
  • Loop through the line character-by-character, and for each one, loop through the possible colours with isAnsiFgColor(), tag each character appropriately. Note that isAnsiFgColor is itself slow compared to just grabbing the raw server output.
I think both methods would be rather slow, though I admit I haven't tried them yet.

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

Re: Mudlet API requests

Post by Vadi »

The screendump script (saves all of the buffer to html) implements the second solution, but uses http://mudlet.org/asciidoc/manual.html#getFgColor for that purpose. Here's my latest iteration of the screendump script: http://paste.pocoo.org/show/361426/

I'm in agreement of being allowed to register custom entries for the right-click menu though. Perhaps that function would just pass the line and character of the selection start and end to the function.

Widjet
Posts: 30
Joined: Thu Apr 22, 2010 1:43 am

Re: Mudlet API requests

Post by Widjet »

I suppose that's fast enough - since I'll be doing it whenever I enter a new room, it has to be pretty quick, but I suspect it wouldn't take more than a hundredth of a second or so.

Is it possible to get the content of the string selected with selectString? I was mucking around with a re-rendering idea, that I had intended could be used like fg(), but I couldn't actually see a way to get the text.

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

Re: Mudlet API requests

Post by Vadi »

I'm not sure what do you mean. You explicitly give selectString the text you'd like selected - it's selectCaptureGroup and selectSection that you don't know what the text was.

Widjet
Posts: 30
Joined: Thu Apr 22, 2010 1:43 am

Re: Mudlet API requests

Post by Widjet »

This is more for a potential library/API thing - I want the user of my function to select the string so they can choose to select it with either selectCaptureGroup, selectString or selectSection. For example:
--What I write
function encode(console)
--Get the string content, encode it on screen.
end

--What they write
selectString(line)
encode('main')
It doesn't really matter - at the moment, I've changed it so that encode takes as a parameter a string to be selected with selectString. But it just feels a bit odd that I can't write the encode function to be similar to the fg() built-in function.

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

Re: Mudlet API requests

Post by Vadi »

I see what you mean, perhaps a function that returns the current selection in plaintext would be useful. You might make a hacky workaround using copy() and a buffer as well.

I don't know if you're aiming this to be high-level (ie cecho) or lowlevel (ie selectString, bg, deselect, resetFormat). Personally, I'd like the convenience of a highlevel, so that I can specify:

encode('main', 'mytext')
encode('main', 3) -- single digit means I want capture group 3
encode('main', 10, 15) -- two digits means I want a selection from the 10th character until the 15th

Widjet
Posts: 30
Joined: Thu Apr 22, 2010 1:43 am

Re: Mudlet API requests

Post by Widjet »

Okay, probably dreaming with this one, but would it be possible to have events for mouse movements or at least mouse entering/exiting specified areas?
I can imagine something like:
Code: [show] | [select all] lua
addMouseEntryListener({x = 30, y = 30, width = 100, height = 100}, "highlightMyButton()")
addMouseExitListener({x = 30, y = 30, width = 100, height = 100}, "dimMyButton()")

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

Re: Mudlet API requests

Post by Vadi »

Doesn't seem to be possible yet. Would be easy to patch the source, add an event and see if that has a performance impact if it's done for every mouse move and you compute on the Lua side whenever you want to raise an event or not... if that's too slow, could be done inside core Mudlet. I agree with the idea in general.

Yetzederixx
Posts: 186
Joined: Sun Nov 14, 2010 5:57 am

Re: Mudlet API requests

Post by Yetzederixx »

Maybe this is already possible and I don't know how to do it, but perhaps a way to promote/demote an item (trigger, alias, etc) up or down the list without having to move all the rest would be in order. I made a configuration trigger today that registers off my MUD's MoTD and had to move all my other triggers, one at a time also, below it.

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

Re: Mudlet API requests

Post by Vadi »

You can just select and drag it?

Post Reply