Skip to content

TableMaker examples

Damian Monogue edited this page Aug 13, 2019 · 4 revisions

Or: How about we just show you how it works?

To create a basic starting table with default options, all we have to do is

testMaker = demonnic.TableMaker:new()
-- Though by itself, it won't really do much. So let's add a few columns to it
testMaker:addColumn({name = "col1", width = 15, textColor = "<orange>"})
testMaker:addColumn({name = "col2", width = 20, textColor = "<green>"})
testMaker:addColumn({name = "col3", width = 30, textColor = "<purple>"})
-- These are fairly minimal format options, but are enough for our demonstration purposes. 
-- So now we've described the formatting for our table, let's add some information to display and print it out.
testMaker:addRow({"row 1 col 1", "row 1 col 2", "row 1 col 3"})
testMaker:addRow({"row 2 col 1", "row 2 col 2", "row 2 col 3"})
testMaker:addRow({"row 3 col 1", "row 3 col 2", "row 3 col 3"})
cecho(testMaker:assemble())

Not bad for 8 lines of code, eh? Let's replace that first column with one a little less wide to show word wrap

testMaker:replaceColumn({name = "col1b", width = 10}, 1)
cecho(testMaker:assemble())

Excellent! But those rows are all kind of samey looking, let's replace one

testMaker:replaceRow({"blah", "", "feh"},2)
cecho(testMaker:assemble())

Hmmm, let's see what it looks like without the column headers in place

testMaker.printHeaders = false
cecho(testMaker:assemble())

Alright. Now what if we made the outer frame red?

testMaker.frameColor = "<red>"
cecho(testMaker:assemble())

And now the inner frame, let's make it blue

testMaker.separatorColor = "<blue>"
cecho(testMaker:assemble())

I hope you're starting to see the kinds of things you can do with this, and how it may make formatting large amounts of items for display on your miniconsoles or main console a bit easier. For further information on the options available, please see TableMaker

You can’t perform that action at this time.