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