2018-03-12 08:30:49 +00:00
|
|
|
-- vim: set noexpandtab :miv --
|
2018-03-09 12:54:37 +00:00
|
|
|
tree = (tab, level=0, skip="") ->
|
|
|
|
if level==0
|
|
|
|
print "┐"
|
|
|
|
|
|
|
|
pre = (lvl, skip) ->
|
|
|
|
for i=1,lvl
|
|
|
|
if skip\sub(i,i) == "y"
|
2018-03-12 08:30:49 +00:00
|
|
|
io.write " "
|
2018-03-09 12:54:37 +00:00
|
|
|
else
|
|
|
|
io.write "│ "
|
|
|
|
|
|
|
|
for idx, element in ipairs tab
|
|
|
|
last = idx == #tab
|
|
|
|
switch type element
|
|
|
|
when "table"
|
|
|
|
pre level, skip
|
|
|
|
io.write last and "└─" or "├─"
|
|
|
|
print element.title and "┬─ "..element.title or "┐"
|
|
|
|
tree element, level+1, skip .. (last and "y" or "n")
|
|
|
|
else
|
|
|
|
pre level, skip
|
|
|
|
if idx<#tab
|
|
|
|
print "├─ "..element
|
|
|
|
else
|
|
|
|
print "└─ "..element
|
|
|
|
|
|
|
|
import max from math
|
|
|
|
column = (col) ->
|
2018-03-12 08:30:49 +00:00
|
|
|
if type(col)!="table" then col = {col}
|
2018-03-09 12:54:37 +00:00
|
|
|
pad = (str, len) ->
|
|
|
|
str..string.rep(" ", len-#str)
|
|
|
|
width = 0
|
|
|
|
for box in *col
|
2018-03-12 08:30:49 +00:00
|
|
|
if type(box)!="table" then box = {box}
|
2018-03-09 12:54:37 +00:00
|
|
|
for elem in *box
|
|
|
|
width = max(width, #elem)
|
|
|
|
|
|
|
|
print "┌─"..string.rep("─",width).."─┐"
|
|
|
|
for idx,box in ipairs(col)
|
2018-03-12 08:30:49 +00:00
|
|
|
if type(box)!="table" then box={box}
|
2018-03-09 12:54:37 +00:00
|
|
|
last = idx==#col
|
|
|
|
for elem in *box
|
|
|
|
io.write "│ "
|
|
|
|
io.write pad elem, width
|
|
|
|
io.write " │"
|
|
|
|
print!
|
|
|
|
unless last
|
|
|
|
print "├─"..string.rep("─",width).."─┤"
|
|
|
|
print "└─"..string.rep("─",width).."─┘"
|
|
|
|
|
|
|
|
box = (box) ->
|
|
|
|
column { box }
|
|
|
|
|
|
|
|
draw = ->
|
|
|
|
for line in * {
|
|
|
|
{ "─", "│", "┼" }
|
|
|
|
{ "┌", "┐", "└", "┘" }
|
2018-07-11 13:59:04 +00:00
|
|
|
{ "├", "┤", "┬", "┴" }
|
|
|
|
{ "╼" ,"╽" ,"╾" ,"╾" }
|
2018-03-09 12:54:37 +00:00
|
|
|
}
|
2018-07-11 13:59:04 +00:00
|
|
|
print table.concat(line, " ")
|
2018-03-09 12:54:37 +00:00
|
|
|
|
|
|
|
|
2018-03-12 08:30:49 +00:00
|
|
|
{
|
|
|
|
:tree, :column, :box, :draw
|
|
|
|
-- Aliases
|
|
|
|
col: column
|
|
|
|
}
|