global refactoring

This commit is contained in:
Er2 2022-02-21 21:29:51 +03:00
parent 1b55bb0ba6
commit b080d64053
35 changed files with 209 additions and 742 deletions

91
A/ccp.lua Normal file
View file

@ -0,0 +1,91 @@
return function(argv, con)
local runs = true
local function parseArgs(ln)
local iq, buf, args = false, '', {}
local qt, esc = nil, false
-- helper function
local function psh()
if #buf > 0 then table.insert(args, buf) end
buf, qt = '', nil
end
for i = 1, #ln + 1 do
local v = ln:sub(i, i)
if ((v == ' ' or v == '\n' or v == '\t') and not iq)
or v == ''
then psh()
elseif esc then esc, buf = false, buf.. v
elseif v == '\\' then esc = true
elseif (not qt or qt == v)
and (v == '"' or v == "'")
then psh()
qt, iq = v, not iq
else buf = buf.. v
end
end
return args
end
local cd = 'A:'
await(function()
con.print(cd.. '>')
con.down()
local ln = con.getln()
local argv = parseArgs(ln)
if not argv[1] then -- nothing
elseif argv[1]:lower() == 'dir' then
local cp, f = 0, fsLs(cd)
for _, v in pairs(f) do
if cp + 14 + #cd >= con.w
then con.print '\n'; cp = 0 end
if cp == 0 then cp = #cd
con.print(cd)
else con.print ' : ' end
local i = fsInfo(cd..v)
local n, ext = v:match('(.+)%.(.+)$')
n = n or v
if #n > 8
then con.print(n:sub(1, 6) .. '~1')
elseif #n < 8
then con.print(n ..(' '):rep(8 - #n))
end
con.print ' '
if i.type == 'directory' then con.print '<D>'
elseif i.type == 'symlink' then con.print '<S>'
elseif i.type == 'other' then con.print '<O>'
elseif ext then
con.print(ext:upper():sub(1, 3))
con.print((' '):rep(3 - #ext))
else con.print ' '
end
cp = cp + 14
end
con.print '\n'
elseif argv[1]:match '%u:' then
cd = argv[1]
elseif argv[1]:lower() == 'type' then
con.print(fsRead(argv[2]))
con.print '\n'
else con.println(argv[1].. ': command not found')
end
return not runs
end)
return sh
end

8
A/ver.lua Normal file
View file

@ -0,0 +1,8 @@
return function(argv, con)
con.print('Er2/L '.. VER)
con.print(' On the Love2D '.. table.concat({love.getVersion()}, '.', 1, 3))
con.println(' 20 FEB 22')
local txt = ('Terminal size is %dx%d characters'):format(con.w, con.h)
local sp = (' '):rep((con.w - #txt) / 2)
con.println(sp.. txt ..'\n\n\n')
end