Skip to content

Etomyutikos/cells

Repository files navigation

cells

A Lua module to format text in a grid. cells exposes constructors for rows, columns, and texts. By composing these three concepts, it's possible to express a wide variety of layouts.

A text object accepts as input a string. That string can be returned wrapped to a certain width. In addition, the rendered string can be returned aligned either "left", "right", or "center". If an alignment is specified, the strings returned will be padded to conform to width expectations.

A row arranges all inner content horizontally, whereas a column arranges all inner content vertically. Both rows and columns will grow horizontally until all inner content is rendered, but their widths can be specified. rows and columns accept as input a table of texts, rows, and columns.

In addition, rows and columns can have single characters set as (from the outside-in) margin, border, and padding.

Example

Script:

local cells = require "init"
local column = cells.column
local row = cells.row
local text = cells.text

local lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. " ..
	"Eligendi non quis exercitationem culpa nesciunt nihil aut nostrum " ..
	"explicabo reprehenderit optio amet ab temporibus asperiores quasi " ..
	"cupiditate. Voluptatum ducimus voluptates voluptas?"

local page = column({
	column({
		text("cells").align("center"),
		text("text formatting Lua module").align("center"),
	}),
	row({
		column({
			text("column header 1").align("center"),
			column({
				text(lorem)
			}).padding(" "),
		}).border("."),
		column({
			text("column header 2").align("center"),
			column({
				text(lorem).align("right"),
				text(lorem).align("right"),
			}).padding(" "),
		}).border("."),
	}),
	row({
		text(lorem),
		text(lorem),
		text(lorem),
		text(lorem),
	}).margin(" ").border(".").padding("="),
}).border("*").width(80)

print("")
for _, v in ipairs(page.render()) do
	print(v)
end

Outputs:

********************************************************************************
*                                     cells                                    *
*                          text formatting Lua module                          *
*..............................................................................*
*.           column header 1           ..           column header 2           .*
*.                                     ..                                     .*
*. Lorem ipsum dolor sit amet,         ..         Lorem ipsum dolor sit amet, .*
*. consectetur adipisicing elit.       ..       consectetur adipisicing elit. .*
*. Eligendi non quis exercitationem    ..    Eligendi non quis exercitationem .*
*. culpa nesciunt nihil aut nostrum    ..    culpa nesciunt nihil aut nostrum .*
*. explicabo reprehenderit optio amet  ..  explicabo reprehenderit optio amet .*
*. ab temporibus asperiores quasi      ..      ab temporibus asperiores quasi .*
*. cupiditate. Voluptatum ducimus      ..      cupiditate. Voluptatum ducimus .*
*. voluptates voluptas?                ..                voluptates voluptas? .*
*.                                     ..         Lorem ipsum dolor sit amet, .*
*........................................       consectetur adipisicing elit. .*
*                                       .    Eligendi non quis exercitationem .*
*                                       .    culpa nesciunt nihil aut nostrum .*
*                                       .  explicabo reprehenderit optio amet .*
*                                       .      ab temporibus asperiores quasi .*
*                                       .      cupiditate. Voluptatum ducimus .*
*                                       .                voluptates voluptas? .*
*                                       .                                     .*
*                                       .......................................*
*                                                                              *
* ............................................................................ *
* .==========================================================================. *
* .=Lorem ipsum dolor Lorem ipsum dolor Lorem ipsum dolor Lorem ipsum dolor =. *
* .=sit amet,         sit amet,         sit amet,         sit amet,         =. *
* .=consectetur       consectetur       consectetur       consectetur       =. *
* .=adipisicing elit. adipisicing elit. adipisicing elit. adipisicing elit. =. *
* .=Eligendi non quis Eligendi non quis Eligendi non quis Eligendi non quis =. *
* .=exercitationem    exercitationem    exercitationem    exercitationem    =. *
* .=culpa nesciunt    culpa nesciunt    culpa nesciunt    culpa nesciunt    =. *
* .=nihil aut nostrum nihil aut nostrum nihil aut nostrum nihil aut nostrum =. *
* .=explicabo         explicabo         explicabo         explicabo         =. *
* .=reprehenderit     reprehenderit     reprehenderit     reprehenderit     =. *
* .=optio amet ab     optio amet ab     optio amet ab     optio amet ab     =. *
* .=temporibus        temporibus        temporibus        temporibus        =. *
* .=asperiores quasi  asperiores quasi  asperiores quasi  asperiores quasi  =. *
* .=cupiditate.       cupiditate.       cupiditate.       cupiditate.       =. *
* .=Voluptatum ducimusVoluptatum ducimusVoluptatum ducimusVoluptatum ducimus=. *
* .=voluptates        voluptates        voluptates        voluptates        =. *
* .=voluptas?         voluptas?         voluptas?         voluptas?         =. *
* .==========================================================================. *
* ............................................................................ *
*                                                                              *
********************************************************************************

About

Lua module to format text in a grid

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages