replaced the editor with skex2 because it's infinitely better and works on PsychOS2 now

This commit is contained in:
Izaya 2019-07-28 19:53:25 +10:00
parent be8ba0a40b
commit aa570fcc4e

View File

@ -1,76 +1,108 @@
local tA = {...}
local fn = tA[1]
local b,C,p = {},{},1
local function sC()
if p > #b then
p = #b
end
if p < 1 then
p = 1
local ft, p, fp, ct, il, it, c, C = {}, 1, fp or tA[1] or "", {}, "", {}, "", C -- file table, pointer, filename, command table, input line, input table, command, content
function ct.readfile(fp,rp)
if not fp then return end
if not rp then ft = {} end
local f=io.open(fp,"rb")
if f then
C=f:read("*a")
f:close()
for l in C:gmatch("[^\n]+") do
ft[#ft+1] = l
end
end
function C.i()
p=p-1
sC()
end
function ct.writefile(nfp)
if not nfp then nfp = fp end
print(nfp)
f=io.open(nfp,"wb")
if f then
for k,v in ipairs(ft) do
print(v)
f:write(v.."\n")
end
coroutine.yield()
f:close()
coroutine.yield()
print(f.b)
end
end
function ct.list(s,e)
s,e = s or 1, e or #ft
for i = s,e do
if ft[i] then
print(string.format("%4d\t %s",i,ft[i]))
end
end
end
function ct.sp(np)
np=tonumber(np)
if np then
if np > #ft then
np = #ft
elseif np < 1 then
np = 0
end
p=np
end
end
function ct.pointer(np)
ct.sp(np)
print(string.format("%4d\t %s",p,ft[p]))
end
function ct.insert(np)
ct.sp(np)
while true do
io.write(tostring(p).."] ")
l = io.read()
io.write(string.format("%4d\t ",p))
local l=io.read()
if l == "." then break end
table.insert(b,p,l)
table.insert(ft,p,l)
p=p+1
end
end
function C.l(s,e)
for i = s or 1, e or #b do
print(string.format("%4d\t %s",i,b[i]))
end
end
function C.a()
function ct.append(np)
ct.sp(np)
p=p+1
C.i()
ct.insert()
end
function C.p(n)
p=tonumber(n) or p
sC()
function ct.substitute(np)
ct.sp(np)
table.remove(ft,p)
ct.insert(np)
end
function C.d(n)
n=tonumber(n) or 1
for i = 1, n do
print(table.remove(b,p,i))
function ct.delete(np)
ct.sp(np)
table.remove(ft,p)
end
function ct.filename(np)
if np then fp = np end
print(fp)
end
function C.r(f)
local f = fs.open(f)
if f then
for l in f:read("*a"):gmatch("[^\n]+") do
table.insert(b,p,l)
p=p+1
end
f:close()
end
end
function C.w(f)
local f=fs.open(f,"wb")
if f then
for _,l in ipairs(b) do
f:write(l.."\n")
end
f:close()
end
end
if fn then
C.r(fn)
end
ct.o = ct.readfile
ct.w = ct.writefile
ct.l = ct.list
ct.p = ct.pointer
ct.i = ct.insert
ct.a = ct.append
ct.s = ct.substitute
ct.d = ct.delete
ct.f = ct.filename
ct.readfile(fp)
while true do
io.write("ed> ")
local l,c = io.read(),{}
for w in l:gmatch("%S+") do
c[#c+1] = w
io.write("skex2> ")
il,it=io.read(),{}
for w in il:gmatch("%S+") do
it[#it+1] = w
end
local e=table.remove(c,1)
if e == "q" then
c=table.remove(it,1)
if c == "quit" or c == "q" then
break
elseif C[e] then
C[e](table.unpack(c))
elseif c:sub(1,1) == "!" then
print(pcall(load(c:sub(2))))
elseif ct[c] ~= nil then
ct[c](table.unpack(it))
end
end