2018-03-12 08:30:49 +00:00
|
|
|
|
-- vim: set noexpandtab :miv --
|
2018-08-15 08:22:11 +00:00
|
|
|
|
|
|
|
|
|
-- ┌──────────────────────────┐
|
|
|
|
|
-- │ Generic Helper Functions │
|
|
|
|
|
-- └──────────────────────────┘
|
|
|
|
|
|
|
|
|
|
match_all = (str, pat, init=0) ->
|
|
|
|
|
s,e = str\find(pat, init)
|
|
|
|
|
if s then
|
|
|
|
|
return str\sub(s,e), match_all(str, pat, e+1)
|
|
|
|
|
match_lines = (str) -> match_all(str, '[^\n]+')
|
|
|
|
|
|
2018-08-15 08:56:22 +00:00
|
|
|
|
-- ┌──────────────────┐
|
|
|
|
|
-- │ Actual Functions │
|
|
|
|
|
-- └──────────────────┘
|
|
|
|
|
|
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
|
|
|
|
|
2018-08-15 08:22:11 +00:00
|
|
|
|
pad = (str='', len) ->
|
|
|
|
|
str..string.rep(" ", len-#str)
|
|
|
|
|
|
2018-03-09 12:54:37 +00:00
|
|
|
|
import max from math
|
|
|
|
|
|
2018-08-15 08:22:11 +00:00
|
|
|
|
chktbl = (obj) -> error("Object is not a table", 2) if type(obj) ~= 'table'
|
|
|
|
|
to_tab = (obj) -> type(obj)=='table' and obj or {match_lines tostring obj}
|
2018-03-09 12:54:37 +00:00
|
|
|
|
|
2018-08-15 08:22:11 +00:00
|
|
|
|
tab = (rows) ->
|
|
|
|
|
-- Get Measurements
|
|
|
|
|
chktbl(rows)
|
|
|
|
|
width = {}
|
|
|
|
|
height = {}
|
|
|
|
|
for row, fields in ipairs rows
|
|
|
|
|
chktbl(fields)
|
|
|
|
|
height[row] = 1
|
|
|
|
|
for col, lines in ipairs fields
|
|
|
|
|
lines = to_tab lines
|
|
|
|
|
height[row] = max(height[row], #lines)
|
|
|
|
|
for line in *lines do
|
|
|
|
|
width[col] = max(width[col] or 1, #line)
|
|
|
|
|
fields[col] = lines
|
|
|
|
|
bars = [string.rep('─', i+2) for i in *width]
|
|
|
|
|
-- Top Line
|
|
|
|
|
print '┌'..table.concat(bars, '┬')..'┐'
|
|
|
|
|
-- Rows
|
|
|
|
|
for row, fields in ipairs rows
|
|
|
|
|
for line=1,height[row]
|
|
|
|
|
io.write '│' -- Outer Left Border
|
|
|
|
|
for col, lines in ipairs fields
|
|
|
|
|
io.write ' '..pad(lines[line], width[col])..' '
|
|
|
|
|
io.write '│' if col < #fields
|
|
|
|
|
print '│' -- Outer Left Border
|
|
|
|
|
print '├'..table.concat(bars, '┼')..'┤' unless row == #rows
|
|
|
|
|
print '└'..table.concat(bars, '┴')..'┘'
|
2018-08-15 07:37:08 +00:00
|
|
|
|
|
2018-08-15 08:22:11 +00:00
|
|
|
|
col = (col) -> tab([{elem} for elem in *col])
|
|
|
|
|
row = (row) -> tab{row}
|
|
|
|
|
box = (box) -> tab{{box}}
|
2018-03-09 12:54:37 +00:00
|
|
|
|
|
2018-08-16 06:17:48 +00:00
|
|
|
|
line = (len=80) -> print string.rep('─', len)
|
2018-08-16 06:20:46 +00:00
|
|
|
|
line2 = (len=80) ->
|
|
|
|
|
error('Length must be at least 2 characters', 2) if len < 2
|
|
|
|
|
print '┌'..string.rep('─', len-2)..'┐'
|
|
|
|
|
print '└'..string.rep('─', len-2)..'┘'
|
2018-08-16 06:17:48 +00:00
|
|
|
|
|
2018-07-13 08:19:13 +00:00
|
|
|
|
CLASS = [[
|
|
|
|
|
print vim.col {
|
2018-08-15 08:29:47 +00:00
|
|
|
|
'Class' -- Title
|
2018-07-13 08:19:13 +00:00
|
|
|
|
{
|
|
|
|
|
-- Members
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
-- Methods
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]]
|
|
|
|
|
|
2018-08-15 09:00:23 +00:00
|
|
|
|
DRAW = [[
|
2018-12-03 12:19:36 +00:00
|
|
|
|
─ ━ │ ┃ ┄ ┅ ┆ ┇ ┈ ┉ ┊ ┋ ┌ ┍ ┎ ┏
|
|
|
|
|
┐ ┑ ┒ ┓ └ ┕ ┖ ┗ ┘ ┙ ┚ ┛ ├ ┝ ┞ ┟
|
|
|
|
|
┠ ┡ ┢ ┣ ┤ ┥ ┦ ┧ ┨ ┩ ┪ ┫ ┬ ┭ ┮ ┯
|
|
|
|
|
┰ ┱ ┲ ┳ ┴ ┵ ┶ ┷ ┸ ┹ ┺ ┻ ┼ ┽ ┾ ┿
|
|
|
|
|
╀ ╁ ╂ ╃ ╄ ╅ ╆ ╇ ╈ ╉ ╊ ╋ ╌ ╍ ╎ ╏
|
|
|
|
|
═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟
|
|
|
|
|
╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬ ╭ ╮ ╯
|
2018-12-11 08:16:40 +00:00
|
|
|
|
╰ ╱ ╲ ╳ ╴ ╵ ╶ ╷ ╸ ╹ ╺ ╻ ╼ ╽ ╾ ╿ ]]
|
2018-03-09 12:54:37 +00:00
|
|
|
|
|
2018-12-11 08:16:40 +00:00
|
|
|
|
ARROWS = [[
|
|
|
|
|
← ↑ → ↓ ↔ ↕ ↖ ↗ ↘ ↙ ▲ ▼ ◀ ▶ ➔ ➘
|
|
|
|
|
➙ ➚ ➛ ➜ ➝ ➞ ➟ ➠ ➡ ➢ ➣ ➤ ➥ ➦ ↪ ↩
|
|
|
|
|
↚ ↛ ↜ ↝ ↞ ↟ ↠ ↡ ↢ ↣ ↤ ↦ ↥ ↧ ↨ ↫
|
|
|
|
|
↬ ↭ ↮ ↯ ↰ ↱ ↲ ↴ ↳ ↵ ↶ ↷ ↸ ↹ ↺ ↻
|
|
|
|
|
⟲ ⟳ ↼ ↽ ↾ ↿ ⇀ ⇁ ⇂ ⇃ ⇄ ⇅ ⇆ ⇇ ⇐ ⇑
|
|
|
|
|
⇒ ⇓ ⇔ ⇌ ⇍ ⇏ ⇕ ⇖ ⇗ ⇘ ⇙ ⇙ ⇳ ⇚ ⇛ ⇜
|
|
|
|
|
⇝ ⇞ ⇟ ⇟ ⇟ ⇠ ⇡ ⇢ ⇣ ⇤ ⇥ ⇦ ⇨ ⇩ ⇪ ⇧
|
|
|
|
|
⇫ ⇬ ⇭ ⇮ ⇯ ⇰ ⇱ ⇲ ⇴ ⇵ ⇶ ⇷ ⇸ ⇹ ⇺ ⇺
|
|
|
|
|
⇻ ⇼ ⇽ ⇾ ⇿ ⟰ ⟱ ⟴ ⟵ ⟶ ⟷ ⟸ ⟹ ⟽ ⟾ ⟺
|
|
|
|
|
⟻ ⟼ ⟿ ⤀ ⤁ ⤅ ⤂ ⤃ ⤄ ⤆ ⤇ ⤈ ⤉ ⤊ ⤋ ⤌
|
|
|
|
|
⤍ ⤎ ⤏ ⤐ ⤑ ⤒ ⤓ ⤔ ⤕ ⤖ ⤗ ⤘ ⤙ ⤙ ⤚ ⤛
|
|
|
|
|
⤜ ⤝ ⤞ ⤡ ⤢ ⤣ ⤤ ⤥ ⤦ ⤧ ⤨ ⤩ ⤪ ⤭ ⤮ ⤯
|
|
|
|
|
⤰ ⤱ ⤲ ⤳ ⤻ ⤸ ⤾ ⤿ ⤺ ⤼ ⤽ ⤴ ⤵ ⤶ ⤷ ⤹
|
|
|
|
|
⥀ ⥁ ⥂ ⥃ ⥄ ⥅ ⥆ ⥇ ⥈ ⥉ ⥒ ⥓ ⥔ ⥕ ⥖ ⥗
|
|
|
|
|
⥘ ⥙ ⥚ ⥛ ⥜ ⥝ ⥞ ⥟ ⥠ ⥡ ⥢ ⥣ ⥤ ⥥ ⥦ ⥧
|
|
|
|
|
⥨ ⥩ ⥪ ⥫ ⥬ ⥭ ⥮ ⥯ ⥰ ⥱ ⥲ ⥳ ⥴ ⥵ ⥶ ⥷
|
|
|
|
|
⥸ ⥹ ⥺ ⥻ ➧ ➨ ➩ ➪ ➫ ➬ ➭ ➮ ➯ ➱ ➲ ➳
|
|
|
|
|
➴ ➵ ➶ ➷ ➸ ➹ ➺ ➻ ➼ ➽ ➾ ⬅ ⬆ ⬇ ⏎ ⬎
|
|
|
|
|
⬏ ⬐ ⬑ ☈ ☇ ⍃ ⍄ ⍇ ⍈ ⍐ ⍗ ⍌ ⍓ ⍍ ⍔ ⍏
|
|
|
|
|
⍖ ⍅ ⍆ ⬈ ⬉ ⬊ ⬋ ⬌ ⬍ ⬀ ⬁ ⬂ ⬃ ⬄ ]]
|
2018-03-09 12:54:37 +00:00
|
|
|
|
|
2018-03-12 08:30:49 +00:00
|
|
|
|
{
|
2018-08-16 06:20:46 +00:00
|
|
|
|
:tree, :box, :tab, :col, :row, :line, :line2
|
2018-12-11 08:16:40 +00:00
|
|
|
|
:CLASS, :DRAW, :ARROWS
|
2018-03-12 08:30:49 +00:00
|
|
|
|
-- Aliases
|
2018-08-15 08:22:11 +00:00
|
|
|
|
table: tab
|
2018-03-12 08:30:49 +00:00
|
|
|
|
}
|