darkrc/lua/vim.moon
DarkWiiPlayer 37bdfddcd7 Lua + Improved visual-exec = ♥
changes ─┐
         ├─ Added a folder for lua / moonscript
         ├─┬─ VISUAL-EXEC BINDINGS
         │ ├─ Visual-Enter now tries running as moonscript
         │ └─ Visual-C-Enter tries running as vim command
         ├─ Added Mooncompile command (compiles moonscript in lua folder)
         ├─ Added vim.moon which does nice things :)
         └─┬─ VIM.MOON
           ├─ tree: builds a tree like this one
           ├─ clumn: draws a table-column (useful for class diagrams)
           └─ draw: prints some drawing symbols
2018-03-09 13:54:37 +01:00

61 lines
1.3 KiB
Text

--vim: set noexpandtab :miv--
tree = (tab, level=0, skip="") ->
if level==0
print "┐"
pre = (lvl, skip) ->
for i=1,lvl
if skip\sub(i,i) == "y"
io.write " "
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) ->
pad = (str, len) ->
str..string.rep(" ", len-#str)
width = 0
for box in *col
for elem in *box
width = max(width, #elem)
print "┌─"..string.rep("─",width).."─┐"
for idx,box in ipairs(col)
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 * {
{ "─", "│", "┼" }
{ "┌", "┐", "└", "┘" }
{"├", "┤", "┬", "┴"}
}
print table.concat(line, " ")
{:tree, :column, :box, :draw}