From 833b5f55048153aa5b771a46181fdffa51a77f43 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Sat, 27 May 2017 18:24:44 +0000 Subject: [PATCH] added a mediocre line editor, skex (2) --- configs/everything-noinit.cfg | 1 + configs/everything.cfg | 1 + modules/applications/skex2.lua | 63 ++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 modules/applications/skex2.lua diff --git a/configs/everything-noinit.cfg b/configs/everything-noinit.cfg index 8275e79..fc81ac6 100644 --- a/configs/everything-noinit.cfg +++ b/configs/everything-noinit.cfg @@ -14,6 +14,7 @@ library/readline.lua applications/nshd.lua applications/nshc.lua applications/shutil.lua +applications/skex2.lua applications/luash.lua applications/ircbridge.lua applications/autoluash.lua diff --git a/configs/everything.cfg b/configs/everything.cfg index 2f0295a..fc057cb 100644 --- a/configs/everything.cfg +++ b/configs/everything.cfg @@ -14,6 +14,7 @@ library/readline.lua applications/nshd.lua applications/nshc.lua applications/shutil.lua +applications/skex2.lua applications/luash.lua applications/ircbridge.lua applications/autoluash.lua diff --git a/modules/applications/skex2.lua b/modules/applications/skex2.lua new file mode 100644 index 0000000..1f3e2ac --- /dev/null +++ b/modules/applications/skex2.lua @@ -0,0 +1,63 @@ +function skex(s,f) + local c,cs,cT,lT,lP="","",{},{},1 + if s then + if f then + c=s + else + local f=fopen(s,"rb") + local nc=fread(f,2048) + while nc ~= nil and nc ~= "" do + c=c..nc + nc=fread(f,2048) + end + end + for l in c:gmatch("(.-)\n") do lT[#lT+1]=l end + end + while true do + cs=readln() + cT={} + for w in cs:gmatch("%S+") do cT[#cT+1]=w end + if cT[1] == "q" then break + elseif cT[1] == "l" then + for i = (TN(cT[2]) or 1), (TN(cT[3]) or #lT) do + print(TS(i).."\t"..(lT[i] or "")) + end + elseif cT[1] == "a" or cT[1] == "i" or cT[1] == "s" then + if TN(cT[2]) then lP=TN(cT[2]) end + if cT[1] == "s" then for i = 1,TN(cT[3]) do T.remove(lT,i+(TN(cT[2])-1)) end end + if cT[1] == "a" then lP=lP+1 end + while true do + cs=readln() + if cs~="." then + T.insert(lT,lP,cs) + lP=lP+1 + else break end + end + elseif cT[1] == "f" then + s=cT[2] or s + print(s) + elseif cT[1] == "e" then + c="" + for k,v in ipairs(lT) do c=c..v.."\n" end + print(pcall(load(c))) + elseif cT[1] == "w" then + f=fopen(s,"wb") + c="" + for k,v in ipairs(lT) do fwrite(f,v.."\n") end + fclose(f) + elseif cT[1] == "d" then + for i = 1, TN(cT[3])-TN(cT[2]) do + T.remove(lT,cT[2]) + end + elseif cT[1] == "p" then + nPT=TN(cT[2]) + if nPT then + lP=nPT + else + print(lP) + end + else + print("?") + end + end +end