2018-03-12 08:30:49 +00:00
|
|
|
-- vim: set noexpandtab :miv --
|
2018-07-13 08:19:13 +00:00
|
|
|
tree = (tab, pref='') ->
|
|
|
|
print tab.title and tab.title or '┐'
|
2018-03-09 12:54:37 +00:00
|
|
|
|
|
|
|
for idx, element in ipairs tab
|
|
|
|
last = idx == #tab
|
2018-07-13 08:19:13 +00:00
|
|
|
first = idx == 1
|
|
|
|
io.write pref
|
|
|
|
io.write last and "└─" or "├─"
|
2018-03-09 12:54:37 +00:00
|
|
|
switch type element
|
|
|
|
when "table"
|
2018-07-17 08:44:25 +00:00
|
|
|
tree element, pref .. (last and ' ' or '│ ')
|
2018-03-09 12:54:37 +00:00
|
|
|
else
|
2018-07-13 08:19:13 +00:00
|
|
|
print tostring element
|
2018-03-09 12:54:37 +00:00
|
|
|
|
|
|
|
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 }
|
|
|
|
|
2018-07-13 08:19:13 +00:00
|
|
|
CLASS = [[
|
|
|
|
print vim.col {
|
|
|
|
{ 'Class' } -- Title
|
|
|
|
{
|
|
|
|
-- Members
|
|
|
|
}
|
|
|
|
{
|
|
|
|
-- Methods
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]]
|
|
|
|
|
2018-03-09 12:54:37 +00:00
|
|
|
draw = ->
|
|
|
|
for line in * {
|
|
|
|
{ "─", "│", "┼" }
|
|
|
|
{ "┌", "┐", "└", "┘" }
|
2018-07-11 13:59:04 +00:00
|
|
|
{ "├", "┤", "┬", "┴" }
|
2018-07-13 08:19:13 +00:00
|
|
|
{ "╼", "╽", "╾", "╾" }
|
2018-03-09 12:54:37 +00:00
|
|
|
}
|
2018-07-13 08:19:13 +00:00
|
|
|
print table.concat(line, " ")
|
2018-03-09 12:54:37 +00:00
|
|
|
|
|
|
|
|
2018-03-12 08:30:49 +00:00
|
|
|
{
|
2018-07-13 08:19:13 +00:00
|
|
|
:tree, :column, :box, :draw, :CLASS
|
2018-03-12 08:30:49 +00:00
|
|
|
-- Aliases
|
|
|
|
col: column
|
|
|
|
}
|