diff --git a/.gitignore b/.gitignore index 2ec1d71..0e09691 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *-mini.lua *.swp mini-*.lua +nminiprompt.lua diff --git a/Embedded/command.lua b/Embedded/command.lua new file mode 100644 index 0000000..830ea4c --- /dev/null +++ b/Embedded/command.lua @@ -0,0 +1,82 @@ +do +pwd = "/boot" +local shenv = {} +setmetatable(shenv,{__index=_G}) + +local function simplify(path) + local npath, rstr = {}, "" + for k,v in ipairs(fs.segments(path)) do + if v == ".." then + npath[#npath] = nil + elseif v ~= "." then + npath[#npath+1] = v + end + end + for k,v in pairs(npath) do + rstr = rstr .. "/" .. v + end + return rstr +end +local function lpath(path) + if not path then return end + if path:sub(1,1) == "/" then -- absolute path + return simplify(path) + else + return simplify(pwd.."/"..path) + end +end + +function shenv.ls(path) + path = lpath(path) or pwd + return table.unpack(fs.list(path)) +end +function shenv.mkdir(path) + path = lpath(path) or pwd + return fs.makeDirectory(path) +end +function shenv.rm(path) + path = lpath(path) or pwd + return fs.remove(path) +end +function cd(path) + path = path or "." + pwd = lpath(path) +end +shenv.shutdown = computer.shutdown + +while true do + write(pwd.."> ") + local inp, tWords = read(), {} + for word in inp:gmatch("%S+") do + tWords[#tWords+1] = word + end + if tWords[1] then + if type(shenv[tWords[1]]) == "function" then + local fname = table.remove(tWords,1) + local tres = {pcall(shenv[fname],table.unpack(tWords))} + if tres[1] == true then + table.remove(tres,1) + end + for k,v in pairs(tres) do print(v) end + elseif fs.exists(lpath(tWords[1])) or fs.exists(tostring(lpath(tWords[1]))..".lua") then + local fname = table.remove(tWords,1) + local fobj = fs.open(lpath(fname),"rb") or fs.open(tostring(lpath(fname))..".lua","rb") + if fobj then + local fcontent = fobj:read("*a") + fobj:close() + local tres = {pcall(load(fcontent),table.unpack(tWords))} + if tres[1] == true then + table.remove(tres,1) + end + print(table.unpack(tres)) + else + print("error opening file") + end + elseif load(inp) then + print(pcall(load(inp,"input","t",shenv))) + elseif #tWords > 0 then + print("error: file or builtin function not found") + end + end +end +end diff --git a/Embedded/common-termsetup.lua b/Embedded/common-termsetup.lua new file mode 100644 index 0000000..f1f4f26 --- /dev/null +++ b/Embedded/common-termsetup.lua @@ -0,0 +1,27 @@ +local ga,sa = component.list("gpu")(),component.list("screen")() +GPU = component.proxy(ga) +GPU.bind(sa) + +write = vt100emu(GPU) +function print(...) + for k,v in pairs({...}) do + write(tostring(v).."\n") + end +end +function read() + local sBuffer = "" + repeat + local tSignal = {computer.pullSignal()} + if tSignal[1] == "key_down" then + if tSignal[3] > 31 and tSignal[3] < 127 then + write(string.char(tSignal[3])) + sBuffer = sBuffer .. string.char(tSignal[3]) + elseif tSignal[3] == 8 and tSignal[4] == 14 and sBuffer:len() > 0 then + write("\8 \8") + sBuffer = sBuffer:sub(1,-2) + end + end + until tSignal[1] == "key_down" and tSignal[3] == 13 and tSignal[4] == 28 + write("\n") + return sBuffer +end diff --git a/Embedded/ufs.lua.min b/Embedded/ufs.lua.min new file mode 100644 index 0000000..175d477 --- /dev/null +++ b/Embedded/ufs.lua.min @@ -0,0 +1,6 @@ +{ + {"segments","S"}, + {"path","P"}, + {"fsi","F"}, + {"length","L"}, +}