diff --git a/build.cfg b/build.cfg index 2b35d82..6a49090 100644 --- a/build.cfg +++ b/build.cfg @@ -1,5 +1,5 @@ optimise no -listmods no -test no -log no +listmods yes +test yes +log yes opath kernel.lua diff --git a/build.lua b/build.lua index 45e519a..125bdc6 100755 --- a/build.lua +++ b/build.lua @@ -77,13 +77,13 @@ print(tostring(#tm).." modules loaded.\n") -- Generate source print("Generating source") if cfg.listmods == "yes" then - ss=ss.."modules,_OSVERSION={" + ss=ss.."_MOD,_OSVERSION,_BD={" for k,v in ipairs(tm) do ss=ss..'"'..v..'",' end ss=ss.."}," if _OSVERSION == nil then - ss=ss..'"MultICE '..io.popen("git rev-parse HEAD"):read("*a"):sub(1,7)..'"\n' + ss=ss..'"MultICE '..io.popen("git rev-parse HEAD"):read("*a"):sub(1,7)..'","'..os.date("%Y/%m/%d %H:%M %z")..'"\n' else ss=ss..'"MultICE DR0"\n' end diff --git a/configs/desktop.cfg b/configs/desktop.cfg index d12b4d2..ab95031 100644 --- a/configs/desktop.cfg +++ b/configs/desktop.cfg @@ -1,14 +1,11 @@ base/header.lua -drivers/dterm.lua library/print.lua -drivers/keyboard.lua -library/net.lua library/fs-min.lua library/fs-std.lua library/fs-ext.lua +library/fs-util.lua util/fs-automount.lua +util/sinit.lua applications/shutil.lua -applications/evproxy-srv.lua -applications/evproxy-client.lua applications/luash.lua base/footer.lua diff --git a/configs/everything-debug.cfg b/configs/everything-debug.cfg new file mode 100644 index 0000000..0bae616 --- /dev/null +++ b/configs/everything-debug.cfg @@ -0,0 +1,25 @@ +base/loadlin.lua +base/header.lua +debug/ocemu-display.lua +debug/ocemu-heartbeat.lua +library/print.lua +library/fs-min.lua +library/fs-std.lua +library/fs-util.lua +util/fs-automount.lua +drivers/tty.lua +drivers/kbd.lua +util/autogpu.lua +library/net.lua +net/ping.lua +library/base64.lua +library/fs-ext.lua +library/readline.lua +applications/nshd.lua +applications/nshc.lua +applications/shutil.lua +applications/skex2.lua +applications/luash.lua +applications/ircbridge.lua +applications/autoluash.lua +base/footer.lua diff --git a/configs/everything-noinit.cfg b/configs/everything-noinit.cfg new file mode 100644 index 0000000..c2fd437 --- /dev/null +++ b/configs/everything-noinit.cfg @@ -0,0 +1,23 @@ +base/loadlin.lua +base/header.lua +library/print.lua +library/fs-min.lua +library/fs-std.lua +library/fs-util.lua +util/fs-automount.lua +drivers/tty.lua +drivers/kbd.lua +util/autogpu.lua +library/net.lua +net/ping.lua +library/base64.lua +library/fs-ext.lua +library/readline.lua +applications/nshd.lua +applications/nshc.lua +applications/shutil.lua +applications/skex2.lua +applications/luash.lua +applications/ircbridge.lua +applications/autoluash.lua +base/footer.lua diff --git a/configs/everything.cfg b/configs/everything.cfg new file mode 100644 index 0000000..b89a40c --- /dev/null +++ b/configs/everything.cfg @@ -0,0 +1,24 @@ +base/loadlin.lua +base/header.lua +library/print.lua +library/fs-min.lua +library/fs-std.lua +library/fs-util.lua +util/fs-automount.lua +drivers/tty.lua +drivers/kbd.lua +util/autogpu.lua +library/net.lua +net/ping.lua +library/base64.lua +library/fs-ext.lua +library/readline.lua +applications/nshd.lua +applications/nshc.lua +applications/shutil.lua +applications/skex2.lua +applications/luash.lua +applications/ircbridge.lua +util/sinit.lua +applications/autoluash.lua +base/footer.lua diff --git a/configs/headless.cfg b/configs/headless.cfg new file mode 100644 index 0000000..4848e64 --- /dev/null +++ b/configs/headless.cfg @@ -0,0 +1,13 @@ +base/header.lua +library/print.lua +library/net.lua +library/readline.lua +applications/nshd.lua +applications/luash.lua +applications/shutil.lua +library/fs-min.lua +library/fs-std.lua +library/fs-ext.lua +util/fs-automount-min.lua +util/loadeeprom.lua +base/footer.lua diff --git a/configs/network-terminal.cfg b/configs/network-terminal.cfg index 6f5c71b..734d11b 100644 --- a/configs/network-terminal.cfg +++ b/configs/network-terminal.cfg @@ -1,10 +1,12 @@ base/header.lua -drivers/dterm.lua library/print.lua -drivers/keyboard.lua +drivers/tty.lua +drivers/kbd.lua +util/autogpu.lua library/net.lua -applications/shutil.lua -applications/evproxy-client.lua +library/readline.lua +applications/nshc.lua applications/luash.lua +applications/autoluash.lua util/loadeeprom.lua base/footer.lua diff --git a/doc/build.md b/doc/build.md index 63500cf..6840c43 100644 --- a/doc/build.md +++ b/doc/build.md @@ -1,7 +1,7 @@ # Building MultICE MultICE uses a relatively simple build system. It has been tested on Arch Linux, Debian Linux, OpenOS and Plan9k. ## 1. Choose modules. -The system is made out of modules from the `modules/` directory. When you run the build script, it assembles them, and optionally optomises the code for space. +The system is made out of modules from the `modules/` directory. When you run the build script, it assembles them, and optionally optimises the code for space. There are a number of preconfigured module sets in the `config/` directory, and you can of course you can write your own. The build system defaults to a file called `modules.cfg` in the current directory. You can specify a config file using `--modconfig=file.cfg`. diff --git a/doc/skex2.md b/doc/skex2.md new file mode 100644 index 0000000..cdfc376 --- /dev/null +++ b/doc/skex2.md @@ -0,0 +1,57 @@ +# skex2 + +## interactive line editor + +skex2 is a simple but functional line editor for MultICE. + +### invocation + +To start skex2, simply run skex(filename) from the Lua prompt. + +### usage + +Generally, commands and arguments are entered in the form of `command argument1 argument2 argument3` with the exception of inline execution, which is in the form of `!lua code here`. + +If skex does not understand what you mean, it will output a line with a question mark. + +### commands + +#### q - quit skex2 + +Exits the program. + +#### l \[start\] \[end\] - list contents + +Output the lines from start to end, inclusive. + +#### f \[filename\] - set the filename + +This sets the filename to be used for I/O, or prints the current one. + +#### r \[filename\] - load file + +Reads from *filename* or the current set via **f** + +#### w \[filename\] - write to file + +Writes to *filename* or the current set via **f** + +#### p \[line\] - print or set current line + +As skex2 is a line editor, your pointer is a line, and this either prints the current one or sets a new one. + +#### a \[line\] - append to buffer + +Appends lines after the current line or *line* until a line with only . is entered. + +#### i \[line\] - insert into buffer + +Inserts lines before the current line or *line* until a line with only . is entered. + +#### s \[line\] - replace line + +Removes the current line or *line* and enters insert mode + +#### e - executes the contents of the buffer + +Basically converts it into one big string and loads it. diff --git a/modules.cfg b/modules.cfg index f72ea91..e481b38 100644 --- a/modules.cfg +++ b/modules.cfg @@ -1,18 +1,20 @@ base/header.lua -drivers/dterm.lua library/print.lua -drivers/keyboard.lua -library/net.lua library/fs-min.lua library/fs-std.lua -library/fs-ext.lua library/fs-util.lua -library/base64.lua util/fs-automount.lua -net/ping.lua +drivers/tty.lua +drivers/kbd.lua +util/autogpu.lua +library/net.lua +library/fs-ext.lua +library/readline.lua +library/base64.lua +applications/nshd.lua +applications/nshc.lua applications/shutil.lua -applications/evproxy-srv.lua -applications/evproxy-client.lua -applications/ircbridge.lua applications/luash.lua +applications/ircbridge.lua +applications/autoluash.lua base/footer.lua diff --git a/modules/applications/autoluash.lua b/modules/applications/autoluash.lua new file mode 100644 index 0000000..4b2e155 --- /dev/null +++ b/modules/applications/autoluash.lua @@ -0,0 +1 @@ +luash() diff --git a/modules/applications/evproxy-client.lua b/modules/applications/evproxy-client.lua deleted file mode 100644 index c08f668..0000000 --- a/modules/applications/evproxy-client.lua +++ /dev/null @@ -1,17 +0,0 @@ -function nshc(evPP,nid) - write("\f") - while true do - if ev[1] == "net_msg" then - local V,msg=false,tostring(ev[4]) - if ev[3] == evPP and ev[2] == nid then - if msg:sub(1,3) == "dis" then - h("display",msg:sub(4)) - end - end - elseif ev[1] == "key_down" then - ns(nid,evPP,"key"..tostring(ev[3])) - end - C.yield() - end -end - diff --git a/modules/applications/evproxy-srv.lua b/modules/applications/evproxy-srv.lua deleted file mode 100644 index f567b09..0000000 --- a/modules/applications/evproxy-srv.lua +++ /dev/null @@ -1,20 +0,0 @@ -evPP,tEPs="nsh",{} -s("netsh daemon",function() - while true do - if ev[1] == "net_msg" then - local V,msg=false,tostring(ev[4]) - for k,v in ipairs(tEPs) do if ev[2] == v then V=true end end - if ev[3] == evPP and V then - if msg:sub(1,3) == "key" then - h("key_down",ev[2],tonumber(msg:sub(4)),0) - end - end - elseif ev[1] == "display" then - for k,v in ipairs(tEPs) do - ns(v,evPP,"dis"..tostring(ev[2])) - end - end - C.yield() - end -end) - diff --git a/modules/applications/ircbridge-embedded.lua b/modules/applications/ircbridge-embedded.lua index e56715a..45f01e2 100644 --- a/modules/applications/ircbridge-embedded.lua +++ b/modules/applications/ircbridge-embedded.lua @@ -26,7 +26,7 @@ function ircb(h,p,n) -- host, port if t and f and p and ms then t,f,p,ms = ub64(t),n..":"..ub64(f),ub64(p),ub64(ms) for k,v in ipairs(tM) do - v.broadcast(nP,t,f,p,ms) + v.broadcast(nVL,nP,t,f,p,ms) end end else diff --git a/modules/applications/ircbridge.lua b/modules/applications/ircbridge.lua index bd5022e..716aa3d 100644 --- a/modules/applications/ircbridge.lua +++ b/modules/applications/ircbridge.lua @@ -29,7 +29,7 @@ function ircb(h,p,n) -- host, port if t and f and p and ms then t,f,p,ms = ub64(t),n..":"..ub64(f),ub64(p),ub64(ms) for k,v in ipairs(tM) do - v.broadcast(nP,t,f,p,ms) + v.broadcast(nVL,nP,t,f,p,ms) end end else diff --git a/modules/applications/luash.lua b/modules/applications/luash.lua index f41fbbd..fd7b534 100644 --- a/modules/applications/luash.lua +++ b/modules/applications/luash.lua @@ -1,7 +1,13 @@ +function luash(si) s("lua shell",function() + if _OSVERSION and _BD then + write(_OSVERSION.." (built at ".._BD..")\t") + end + print(tostring(computer.freeMemory()/1024).."K free.",_G.motd) print(_VERSION) while true do - h("display","> ") + write("> ") print(pcall(load(readln()))) end -end) +end,si) +end diff --git a/modules/applications/nshc.lua b/modules/applications/nshc.lua new file mode 100644 index 0000000..b4324be --- /dev/null +++ b/modules/applications/nshc.lua @@ -0,0 +1,30 @@ +function nshc_w(evPP,nid) + local sI = E().sI or 1 + while true do + if ev[1] == "net_msg" then + local V,msg=false,tostring(ev[4]) + if ev[3] == evPP and ev[2] == nid then + if msg:sub(1,3) == "dis" then + write(msg:sub(4)) + end + end + elseif ev[1] == "key" and ev[2] == sI and ev[3] == 29 and ev[4] == 27 then + break + elseif ev[1] == "key" and ev[2] == sI then + ns(nid,evPP,"key"..tostring(ev[3])) + end + C.yield() + end + ns(nid,evPP,"exit") +end + +function nshc(P,nid) + ns(nid,P,"initnsh") + while true do + if ev[1] == "net_msg" and ev[2] == nid and ev[3] == P then + break + end + C.yield() + end + nshc_w(ev[4],nid) +end diff --git a/modules/applications/nshd.lua b/modules/applications/nshd.lua new file mode 100644 index 0000000..2e58b6f --- /dev/null +++ b/modules/applications/nshd.lua @@ -0,0 +1,37 @@ +function nshd_w(evPP,cA,sI) +s("netsh daemon - "..tostring(sI),function() + while true do + if ev[1] == "net_msg" then + local msg=tostring(ev[4]) + if ev[3] == evPP and ev[2] == cA then + if msg:sub(1,3) == "key" then + h("key",tT[cT][3].sI,tonumber(msg:sub(4)),0) + elseif msg == "exit" then pcall(killsession,sI) break + end + end + elseif ev[1] == "display" and ev[3] == tT[cT][3].sI then + ns(cA,evPP,"dis"..tostring(ev[2])) + end + C.yield() + end +end,{["sI"]=sI}) +end + +function nshd(P) + s("nshd",function() + local Cc=1 + while true do + if ev[1] == "net_msg" and ev[3] == P then + if ev[4] == "initnsh" then + nnID="nsh-"..tostring(Cc) + Cc=Cc+1 + ns(ev[2],P,nnID) + nshd_w(nnID,ev[2],nnID) + luash({["sI"]=nnID}) + print("[nshd]Spawned "..nnID.." for "..tostring(ev[2])) + end + end + C.yield() + end + end,{["sI"]="log"}) +end diff --git a/modules/applications/proc-utils.lua b/modules/applications/proc-utils.lua new file mode 100644 index 0000000..a925114 --- /dev/null +++ b/modules/applications/proc-utils.lua @@ -0,0 +1,10 @@ +function pkill(P) + tT[P] = nil +end +function killsession(sI) + for k,v in ipairs(tT) do + if v[3].sI == sI then + pkill(k) + end + end +end diff --git a/modules/applications/shutil.lua b/modules/applications/shutil.lua index 84f397e..7ad4641 100644 --- a/modules/applications/shutil.lua +++ b/modules/applications/shutil.lua @@ -1,10 +1,12 @@ function ps() + local S="" for k,v in pairs(tT) do - print(v[1]) + S=S..("pid: "..tostring(k).."\tname: "..tostring(v[1]).."\tenv={") + for l,w in pairs(v[3]) do S=S..(tostring(l).." = "..tostring(w)..", ") end + S=S.."}\n" end + return S end function mem() - print("Total: "..tostring(computer.totalMemory()/1024).."K") - print("Free: "..tostring(computer.freeMemory()/1024).."K") - print("Used: "..tostring((computer.totalMemory()-computer.freeMemory())/1024).."K") + return "Total:\t"..tostring(computer.totalMemory()/1024).."K\nFree:\t"..tostring(computer.freeMemory()/1024).."K\nUsed:\t"..tostring((computer.totalMemory()-computer.freeMemory())/1024).."K" end diff --git a/modules/applications/skex2.lua b/modules/applications/skex2.lua new file mode 100644 index 0000000..95f5240 --- /dev/null +++ b/modules/applications/skex2.lua @@ -0,0 +1,68 @@ +function skex(s) + local c,cs,cT,lT,lP="","",{},{},1 + local function lf(s) + 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 + local function wf(s) + local f,c=fopen(s,"wb"),"" + for k,v in ipairs(lT) do fwrite(f,v.."\n") end + fclose(f) + end + if s then + lf(s) + 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] == "r" then + s=cT[2] or s + wf(s) + elseif cT[1] == "w" then + s=cT[2] or s + wf(s) + 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 + lP=TN(cT[2]) or lP + print(lP) + elseif cs:sub(1,1) == "!" then + c="" + for k,v in ipairs(lT) do c=c..v.."\n" end + print(pcall(load(cs:sub(2)))) + else + print("?") + end + end +end diff --git a/modules/base/footer.lua b/modules/base/footer.lua index 3da2acd..1cacb73 100644 --- a/modules/base/footer.lua +++ b/modules/base/footer.lua @@ -5,7 +5,7 @@ while #tT > 0 do if C.status(v[2])~="dead" then C.resume(v[2],table.unpack(ev)) else - T.remove(tT,k) + tT[k] = nil end end end diff --git a/modules/base/header.lua b/modules/base/header.lua index 2670606..05bc074 100644 --- a/modules/base/header.lua +++ b/modules/base/header.lua @@ -1,10 +1,14 @@ -tT,p,C,T={},1,coroutine,table -function s(n,f,e) - T.insert(tT,{n,C.create(f),(e or {})}) +tT,p,cT,pC,C,T,TS,TN={},1,1,1,coroutine,table,tostring,tonumber +function E() + if tT[cT] ~= nil then return tT[cT][3] end end function l() - return eV + return ev end function h(...) computer.pushSignal(...) end +function s(n,f,e) + tT[pC]={n,C.create(f),(e or E() or {})} + pC=pC+1 +end diff --git a/modules/base/loadlin.lua b/modules/base/loadlin.lua new file mode 100644 index 0000000..cdd7938 --- /dev/null +++ b/modules/base/loadlin.lua @@ -0,0 +1,9 @@ +if pcall(require,"computer") then + print("OpenOS detected.") + print(os.getenv("_")) + local computer = require "computer" + local process = require "process" + os.execute("cp "..os.getenv("_").." /tmp/init.lua") + computer.setBootAddress(computer.tmpAddress()) + computer.shutdown(true) +end diff --git a/modules/debug/ocemu-display.lua b/modules/debug/ocemu-display.lua new file mode 100644 index 0000000..f40a72a --- /dev/null +++ b/modules/debug/ocemu-display.lua @@ -0,0 +1,8 @@ +s("ocemu display server",function() + while true do + if ev[1] == "display" then + component.invoke(component.list("ocemu")(),"log",ev[2] or "") + end + C.yield() + end +end) diff --git a/modules/debug/ocemu-heartbeat.lua b/modules/debug/ocemu-heartbeat.lua new file mode 100644 index 0000000..d2a7e29 --- /dev/null +++ b/modules/debug/ocemu-heartbeat.lua @@ -0,0 +1,11 @@ +_G.DEBUG=true +s("heartbeat",function() + while true do + if _G.DEBUG then + component.invoke(component.list("ocemu")(),"log","heartbeat:"..tostring(computer.uptime())) + component.invoke(component.list("ocemu")(),"log",T.unpack(ev)) + component.invoke(component.list("ocemu")(),"log","processes:\n"..ps()) + end + C.yield() + end +end) diff --git a/modules/drivers/kbd.lua b/modules/drivers/kbd.lua new file mode 100644 index 0000000..4562b91 --- /dev/null +++ b/modules/drivers/kbd.lua @@ -0,0 +1,10 @@ +function kbd(kA,sI) + s("kbd: "..kA:sub(1,8)..","..tostring(sI),function() + while true do + if ev[1] == "key_down" and ev[2] == kA then + h("key",sI,ev[3],ev[4]) + end + C.yield() + end + end) +end diff --git a/modules/drivers/tty.lua b/modules/drivers/tty.lua new file mode 100644 index 0000000..937a3ca --- /dev/null +++ b/modules/drivers/tty.lua @@ -0,0 +1,35 @@ +function tty(gA,sA,sI,fg,bg) + local gP,cx,cy = component.proxy(gA),1,1 + gP.bind(sA) + local sx, sy = gP.getResolution() + gP.setResolution(sx,sy) + gP.setForeground(bg or 0xFFFFFF) + gP.setBackground(bg or 0x000000) + gP.fill(1,1,sx,sy," ") + local function cv() + if cx > sx then cx,cy=1,cy+1 end + if cx < 1 then cx,cy=1,cy-1 end + if cy < 1 then cx,cy=1,1 end + if cy > sy then gP.copy(1,2,sx,sy-1,0,-1) gP.fill(1,sy,sx,1," ") cx,cy=1,sy end + end + local function wl(str) + for c in str:gmatch(".") do + if c == "\n" then cx,cy=1,cy+1 + elseif c == "\r" then cx=1 + elseif c == "\f" then cx=1 cy=1 gP.fill(1, 1, sx, sy, " ") + elseif c == "\t" then cx=(cx+4-((cx+4)%4))+1 + elseif c == "\127" then cx=cx-1 gP.set(cx,cy," ") + else gP.set(cx,cy,c) cx=cx+1 + end cv() + end + end + s("tty: "..gA:sub(1,8)..","..sA:sub(1,8),function() + while true do + eT = ev + if eT[1] == "display" and eT[3] == sI then + wl(tostring(eT[2])) + end + C.yield() + end + end) +end diff --git a/modules/library/base64-passthrough.lua b/modules/library/base64-passthrough.lua new file mode 100644 index 0000000..6f552b6 --- /dev/null +++ b/modules/library/base64-passthrough.lua @@ -0,0 +1,6 @@ +function b64(data) + return component.invoke(component.list("data")(),"encode64",data) +end +function ub64(data) + return component.invoke(component.list("data")(),"decode64",data) +end diff --git a/modules/library/fs-std.lua b/modules/library/fs-std.lua index 5fec249..8988f32 100644 --- a/modules/library/fs-std.lua +++ b/modules/library/fs-std.lua @@ -21,6 +21,14 @@ function fread(h,n) end return false end +function freadall(f) + local s="" + repeat + c=fread(f,2048) + s=s..c + until c=="" + return s +end function fwrite(h,d) if hT[h] then return hT[h][1].write(hT[h][2],d) diff --git a/modules/library/fs-util.lua b/modules/library/fs-util.lua index a7b5ea5..408b0ce 100644 --- a/modules/library/fs-util.lua +++ b/modules/library/fs-util.lua @@ -17,14 +17,9 @@ function fmove(i,o) frm(i) end function fload(i) - local f,s = fopen(i,"rb"),"" + local f = fopen(i,"rb") if f then - local c=fread(f,math.huge) - repeat - s=s..c - c=fread(f,math.huge) - until c == nil - load(s) + return load(freadall(f)) end return false end diff --git a/modules/library/net.lua b/modules/library/net.lua index 527ce77..fd79abe 100644 --- a/modules/library/net.lua +++ b/modules/library/net.lua @@ -1,4 +1,4 @@ -tM,nP,nID,nVL = {}, 4096, computer.address(), 1 +tM,nP,nID,nVL = {}, 4096, computer.address():sub(1,8), 1 for a,t in component.list("modem") do table.insert(tM,component.proxy(a)) component.proxy(a).open(nVL) diff --git a/modules/library/print.lua b/modules/library/print.lua index fc167bf..5eee2d4 100644 --- a/modules/library/print.lua +++ b/modules/library/print.lua @@ -1,10 +1,10 @@ -function print(...) - for k,v in pairs({...}) do - h("display",tostring(v).."\n") - end -end function write(...) for k,v in pairs({...}) do - h("display",tostring(v)) + h("display",tostring(v),E().sI or 1) + end +end +function print(...) + for k,v in pairs({...}) do + write(tostring(v).."\n") end end diff --git a/modules/library/readline.lua b/modules/library/readline.lua new file mode 100644 index 0000000..7ca4433 --- /dev/null +++ b/modules/library/readline.lua @@ -0,0 +1,19 @@ +function readln() + local s,si="",E().sI or 1 + write("|") + while true do + if ev[1] == "key" and ev[2] == si then + if ev[3] == 13 then + write("\127\n") + C.yield() + return s + elseif ev[3] == 8 then + if s:len()>0 then s=s:sub(1,-2) write("\127\127|") end + elseif ev[3] > 31 and ev[3] < 127 then + s=s..string.char(ev[3]) write("\127"..string.char(ev[3]).."|") + end + end + C.yield() + end +end + diff --git a/modules/util/autogpu.lua b/modules/util/autogpu.lua new file mode 100644 index 0000000..1789539 --- /dev/null +++ b/modules/util/autogpu.lua @@ -0,0 +1,2 @@ +tty(component.list("gpu")(),component.list("screen")(),1) +kbd(component.list("keyboard")(),1) diff --git a/modules/util/sinit.lua b/modules/util/sinit.lua new file mode 100644 index 0000000..4616be6 --- /dev/null +++ b/modules/util/sinit.lua @@ -0,0 +1,13 @@ +s("init",function() + local f=fopen("boot:/init.cfg","rb") + write("") + if f then + local c=freadall(f) + for l in c:gmatch("[^\n]+") do + write("[init] "..l..": ") + local pf=fload(l) + print(pcall(pf)) + C.yield() + end + end +end) diff --git a/strip.lua b/strip.lua index cb8e3db..4428a89 100644 --- a/strip.lua +++ b/strip.lua @@ -25,6 +25,8 @@ replacements={ {"%-%-.-\n",""}, {"coroutine%.","C."}, {"table%.","T."}, +{"tostring","TS"}, +{"tonumber","TN"}, } for k,v in ipairs(replacements) do while ss:find(v[1]) ~= nil do