Page 1 of 2

fText, the text formatting library

Posted: Sat Jul 13, 2019 7:20 pm
by demonnic
Releases now being kept at https://github.com/demonnic/fText/releases.

I'm keeping the xml package for this on my github at https://github.com/demonnic/MiscMudlet under the name fText.xml .
I've moved the documentation to the wiki. Updating the forum post is a pain in the butt, and I just feel more comfortable trying to document and give examples for this sort of thing on the wiki. So, for documentation, go here: https://github.com/demonnic/fText/wiki

Some of you may be familiar with this thing I made a while back for formatting text. I named it 'align' and wrote it completely in the global namespace which, looking back, I regret. Someone recently asked about some updates to it, and I looked over the code, and I was embarrassed. So I rewrote the whole thing, and included word wrapping of a sort.

It also has a reusable formatter object, which keeps internal track of its formatting options so you can use it to format any text the same way over and over.

It now also has a tablemaker, allowing you to make spreedsheat like tables to display information in a miniconsole or in your main console.

Now! It has some limitations. You shouldn't try to control the color inside of the string you're formatting if you're going to do wordwrapping yet. I intend to do that eventually but right now it just isn't going to work very well. I provide options for coloring the caps, spacers, and text in the meantime. And I'm only stripping the c| form of hex coloring from strings for the purposes of determining the string's actual length... I haven't figured out the pattern for doing that and # both yet. I imagine that will go in around the same time as I handle maintaining color instructions inside the string being passed for formatting.

And now, some pictures just generally showing what it can do.
fText2.png
tablemaker.png

Re: fText(), the next iteration of align()

Posted: Wed Aug 07, 2019 4:41 am
by demonnic
I have updated this, though I have not really changed the underlying functionality. I have however now included a reusable TextFormatter object. You create it using demonnic.TextFormatter:new(tableOfOptions) . In this case, the tableOfOptions should be the same as the second argument to the align/fText line of functions, and will be reused for formatting. You then use the format(stringToFormat) function of the newly created object to get back a formatted message. So for instance, the code
Code: [show] | [select all] lua
myFormatter = demonnic.TextFormatter:new( {
  width = 40, 
  cap = "[CAP]",
  capColor = "<orange>",
  textColor = "<light_blue>"
})
myMessage = "This is a test of the emergency broadcasting system. This is only a test"
cecho(myFormatter:format(myMessage))
produces the following:
Screenshot from 2019-08-07 00-33-26.png
Screenshot from 2019-08-07 00-33-26.png (5.14 KiB) Viewed 12189 times
If you were to then do
Code: [show] | [select all] lua
myFormatter:setCapColor("<green>")
cecho(myFormatter:format(myMessage))
You would get:
Screenshot from 2019-08-07 00-35-22.png
Screenshot from 2019-08-07 00-35-22.png (4.38 KiB) Viewed 12189 times
I have included functions to set all the valid options for the align/ftext functions. You can also view or set the options of the formatter directly in the options table it holds, for example:
Code: [show] | [select all] lua
display(myFormatter.options)
myFormatter.options.capColor = "<green>"
However, I recommend using the set functions which provide type checking and more error handling.

Re: fText(), the next iteration of align()

Posted: Tue Aug 13, 2019 4:35 am
by demonnic
I have updated this. It now also include a table maker!
Check it out here: https://github.com/demonnic/fText/wiki/ ... r-examples

Re: fText, the text formatting library

Posted: Wed Aug 14, 2019 4:04 am
by demonnic
New update, adds setCell for the TableMaker, and deleteRow/deleteColumn.

It also allows you to use functions for cell entries, so long as those functions return cells.

Also, I do not deepcopy the tables added via TableMaker:addRow(), which means if you update the original table, the value in the TableMaker will change. IE
Code: [show] | [select all] lua
myStats = { "50", "75", "82" }
myTableMaker:addRow(myStats)
-- now as you update myStats, the new entries will be reflected in the output of myTableMaker:assemble(). 
-- iow, you can update and reprint the table by doing
myStats[1] = "30"
cecho(myTableMaker:assemble())

Re: fText, the text formatting library

Posted: Mon Aug 26, 2019 12:30 am
by demonnic
New Update! This one won't work unless you use the latest development snapshot from https://make.mudlet.org/snapshots or wait for Mudlet 4.1 for the new functions I'm relying on for the functionality, but now you can embed echoLink and echoPopup output in the table, allowing for the easier creation of interactive miniconsole interfaces. Brief demo video: https://youtu.be/_XnaJlkI7WM

The code that makes the first plaintext table is:
Code: [show] | [select all] lua
testCon = testCon or Geyser.MiniConsole:new({ x = 100, width = "69c", height = "9c"})
testCon:resize("69c", "9c")
testCon:setFontSize(12)
testMaker3 = demonnic.TableMaker:new({
  autoClear = true,
	allowPopups = true,
})
testMaker3:setAutoEchoConsole(testCon)
testMaker3:addColumn({name = "col1", width = 15, textColor = "<orange>"})
testMaker3:addColumn({name = "col2", width = 20, textColor = "<green>"})
testMaker3:addColumn({name = "col3", width = 30, textColor = "<purple>"})
testMaker3:addRow({"row 1 col 1", "row 1 col 2", "row 1 col 3"})
testMaker3:addRow({"row 2 col 1", "row 2 col 2", "row 2 col 3"})
testMaker3:addRow({"row 3 col 1", "row 3 col 2", "row 3 col 3"})
testMaker3:assemble()
And the code to turn it into the popup/link version in the second part of the video:
Code: [show] | [select all] lua
testMaker3:setCell(2,3,{"r2c3", {[[send("sit")]], [[send("stand")]]}, {"siddown!", "standup!"}})
testMaker3:setCell(1,1,{"Siddown", [[send("sit")]], "siddown!", false})
testCon:resize("69c", "11c")
testMaker3:setCell(2,2,"Peter piper picked a peck of pickled peppers")
testMaker3:assemble()
So if you want to use an echoLink, you pass a table for the row instead of a string. {"this is the message", [[send("sit")]], "sit"} . You construct the table the same way you would the parameters to echoLink. Same with if you want to use a popup, {"this is the message", {[[send("sit")]], [[send("stand")]]}, {"sit", "stand"}}

Re: fText, the text formatting library

Posted: Tue Feb 25, 2020 12:02 am
by Saros
This looks awesome.

Thanks!

Re: fText, the text formatting library

Posted: Thu Mar 19, 2020 9:03 pm
by demonnic
New release located at https://github.com/demonnic/fText/releases/latest

I was writing tests for fText to test my LuaUnit hacks and discovered a major bug in fText with left/right aligned text being 1 character too short.

This and future released of fText will have to pass the unit tests before they make it out to you fine folks. Sorry to anyone who'd been tripped up by this error on my part!

Re: fText, the text formatting library

Posted: Thu Mar 19, 2020 9:05 pm
by demonnic
Saros wrote:
Tue Feb 25, 2020 12:02 am
This looks awesome.

Thanks!
Sorry I didn't see this sooner, but you're definitely welcome =)

Re: fText, the text formatting library

Posted: Sat May 02, 2020 7:03 pm
by Thodak
Thanks for this, it looks awesome. I'm new to Lua programming.
I tried to change the color using a hex string:
Code: [show] | [select all] lua
myFormatter:setCapColor("#9AC48D")
But it didn't change the color. Is there a way to specify CAP color in fText via hex strings?

Re: fText, the text formatting library

Posted: Sun May 03, 2020 3:03 pm
by demonnic
if you set formatType to 'h' then it should be setup for hex colors then