forked from Hyperion/HyperionOS
NC firmware update (thanks spsf). opencomputers now uses mutiple gpus to speed up rendering and now has net drivers. currently working on kernel memory protections to prevent malicious kernel drivers. spm does not work on opencomputers, this is a known issue i am working on fixing it :D sorry for the slow development.
This commit is contained in:
1 parent
fbaafc7cff
commit
ef4b856ee6
89 files changed
+3955
-563
No files matched your search
+115
-12
@@ -156,17 +156,18 @@ local function copyfile(src, dst)
|
||||
return true
|
||||
end
|
||||
|
||||
local function rmtree(path)
|
||||
local function rmtree(path, p)
|
||||
local t = syscall.type(path)
|
||||
if t == "directory" then
|
||||
local ok, list = pcall(syscall.listdir, path)
|
||||
if ok then
|
||||
for _, e in ipairs(list) do
|
||||
rmtree(path:gsub("/$","").."/"..e)
|
||||
rmtree(path:gsub("/$","").."/"..e, p)
|
||||
end
|
||||
end
|
||||
end
|
||||
if t then pcall(syscall.remove, path) end
|
||||
if p then print(path) end
|
||||
end
|
||||
|
||||
local function copytree(src, dst)
|
||||
@@ -334,7 +335,7 @@ builtinCmds.mkdir = function(...)
|
||||
end
|
||||
|
||||
builtinCmds.rm = function(...)
|
||||
local opts, args = parseargs({...}, "rRf")
|
||||
local opts, args = parseargs({...}, "rRfv")
|
||||
if #args == 0 then print("rm: missing operand"); return end
|
||||
local recursive = opts.r or opts.R
|
||||
for _, a in ipairs(args) do
|
||||
@@ -344,10 +345,11 @@ builtinCmds.rm = function(...)
|
||||
if not opts.f then print("rm: cannot remove '"..a.."': No such file or directory") end
|
||||
elseif t == "directory" then
|
||||
if not recursive then print("rm: cannot remove '"..a.."': Is a directory")
|
||||
else rmtree(path) end
|
||||
else rmtree(path, opts.v) end
|
||||
else
|
||||
local ok, err = pcall(syscall.remove, path)
|
||||
if not ok then print("rm: cannot remove '"..a.."': "..tostring(err)) end
|
||||
if opts.v then print("Removed: "..path) end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -888,6 +890,74 @@ local function listCommands(prefix)
|
||||
return results
|
||||
end
|
||||
|
||||
local cacheGen = 0
|
||||
local cmdCache = { gen = -1, list = {} }
|
||||
local dirCache = {}
|
||||
local cachedPath = nil
|
||||
local cachedCwd = nil
|
||||
|
||||
local function invalidateCaches()
|
||||
cacheGen = cacheGen + 1
|
||||
cachedPath = nil
|
||||
cachedCwd = nil
|
||||
end
|
||||
|
||||
local function currentPath()
|
||||
if not cachedPath then cachedPath = syscall.getEnviron("PATH") or "/bin/" end
|
||||
return cachedPath
|
||||
end
|
||||
|
||||
local function currentDir()
|
||||
if not cachedCwd then cachedCwd = syscall.getcwd() end
|
||||
return cachedCwd
|
||||
end
|
||||
|
||||
local function cachedCommandNames()
|
||||
if cmdCache.gen ~= cacheGen then
|
||||
local seen = {}
|
||||
local results = {}
|
||||
for name in pairs(builtinCmds) do
|
||||
if not seen[name] then results[#results+1] = name; seen[name] = true end
|
||||
end
|
||||
for _, p in ipairs(string.split(currentPath(), ":")) do
|
||||
local ok, entries = pcall(syscall.listdir, p)
|
||||
if ok and entries then
|
||||
for _, e in ipairs(entries) do
|
||||
if not seen[e] then results[#results+1] = e; seen[e] = true end
|
||||
end
|
||||
end
|
||||
end
|
||||
table.sort(results)
|
||||
cmdCache.list = results
|
||||
cmdCache.gen = cacheGen
|
||||
end
|
||||
return cmdCache.list
|
||||
end
|
||||
|
||||
local function filterByPrefix(list, prefix)
|
||||
local out = {}
|
||||
for _, c in ipairs(list) do
|
||||
if prefix == "" or c:sub(1, #prefix) == prefix then out[#out+1] = c end
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
local function cachedDirList(dir)
|
||||
local e = dirCache[dir]
|
||||
if not e or e.gen ~= cacheGen then
|
||||
local count = 0
|
||||
for _ in pairs(dirCache) do count = count + 1 end
|
||||
if count > 32 then dirCache = {} end
|
||||
local ok, list = pcall(listDir, dir, "")
|
||||
if ok and list then
|
||||
e = { gen = cacheGen, list = list }
|
||||
dirCache[dir] = e
|
||||
end
|
||||
end
|
||||
if e then return e.list end
|
||||
return {}
|
||||
end
|
||||
|
||||
local function commonPrefix(list)
|
||||
if #list == 0 then return "" end
|
||||
local pre = list[1]
|
||||
@@ -1019,6 +1089,8 @@ local function getUserInput()
|
||||
local cursorPos = 1
|
||||
local history = 0
|
||||
local dirty = true
|
||||
local contentChanged = true
|
||||
local ghostText = ""
|
||||
|
||||
local function getGhostSuffix()
|
||||
if #input == 0 then return "" end
|
||||
@@ -1027,22 +1099,22 @@ local function getUserInput()
|
||||
local candidates
|
||||
if isFirst then
|
||||
if partialDir then
|
||||
local dir = partialDir:sub(1,1) == "/" and partialDir or (syscall.getcwd().."/"..partialDir)
|
||||
candidates = listDir(dir, partialBase)
|
||||
local dir = partialDir:sub(1,1) == "/" and partialDir or (currentDir().."/"..partialDir)
|
||||
candidates = filterByPrefix(cachedDirList(dir), partialBase)
|
||||
for i, c in ipairs(candidates) do candidates[i] = partialDir..c end
|
||||
else
|
||||
candidates = listCommands(partialBase)
|
||||
candidates = filterByPrefix(cachedCommandNames(), partialBase)
|
||||
end
|
||||
else
|
||||
local dir, base
|
||||
if partialDir then
|
||||
dir = partialDir:sub(1,1) == "/" and partialDir or (syscall.getcwd().."/"..partialDir)
|
||||
dir = partialDir:sub(1,1) == "/" and partialDir or (currentDir().."/"..partialDir)
|
||||
base = partialBase
|
||||
else
|
||||
dir = syscall.getcwd()
|
||||
dir = currentDir()
|
||||
base = partialBase
|
||||
end
|
||||
candidates = listDir(dir, base)
|
||||
candidates = filterByPrefix(cachedDirList(dir), base)
|
||||
if partialDir then
|
||||
for i, c in ipairs(candidates) do candidates[i] = partialDir..c end
|
||||
end
|
||||
@@ -1069,7 +1141,11 @@ local function getUserInput()
|
||||
syscall.devctl(1,"sfgc",0xFFFFFF); syscall.devctl(1,"sbgc",0x000000)
|
||||
local after = string.sub(input, cursorPos+1)
|
||||
syscall.write(1, after)
|
||||
local ghost = getGhostSuffix()
|
||||
if contentChanged then
|
||||
ghostText = getGhostSuffix()
|
||||
contentChanged = false
|
||||
end
|
||||
local ghost = ghostText
|
||||
if #ghost > 0 then
|
||||
syscall.devctl(1,"sfgc",0x6D00FF)
|
||||
syscall.write(1, ghost)
|
||||
@@ -1080,8 +1156,27 @@ local function getUserInput()
|
||||
end
|
||||
end
|
||||
|
||||
local function redrawCursorOnly()
|
||||
local ok, tw = pcall(syscall.devctl, 1, "size")
|
||||
if not ok or type(tw) ~= "number" then tw = 80 end
|
||||
local total = (curOffsetX-1) + (cursorPos-1)
|
||||
local y = curOffsetY + math.floor(total/tw)
|
||||
local x = (total%tw)+1
|
||||
syscall.devctl(1,"spos",x,y)
|
||||
if blinkState then
|
||||
syscall.devctl(1,"sfgc",0x000000); syscall.devctl(1,"sbgc",0xFFFFFF)
|
||||
end
|
||||
if cursorPos > #input then
|
||||
syscall.write(1, " ")
|
||||
else
|
||||
syscall.write(1, string.sub(input, cursorPos, cursorPos))
|
||||
end
|
||||
syscall.devctl(1,"sfgc",0xFFFFFF); syscall.devctl(1,"sbgc",0x000000)
|
||||
end
|
||||
|
||||
while true do
|
||||
local key = syscall.read(0)
|
||||
local beforeInput, beforeCursor = input, cursorPos
|
||||
if key and key ~= "" then
|
||||
if key=="[D" then if cursorPos>1 then cursorPos=cursorPos-1;dirty=true end
|
||||
elseif key=="[C" then if cursorPos<=#input then cursorPos=cursorPos+1;dirty=true end
|
||||
@@ -1110,6 +1205,7 @@ local function getUserInput()
|
||||
local newInput, newCursor, needsRedraw = doTabComplete(input, cursorPos)
|
||||
if needsRedraw then
|
||||
input = newInput; cursorPos = newCursor
|
||||
contentChanged = true
|
||||
local px,py = syscall.devctl(1, "gpos")
|
||||
if px > 1 then
|
||||
syscall.devctl(1,"spos",1,py)
|
||||
@@ -1138,10 +1234,16 @@ local function getUserInput()
|
||||
input=string.sub(input,1,cursorPos-1)..key..string.sub(input,cursorPos)
|
||||
cursorPos=cursorPos+1;dirty=true
|
||||
end
|
||||
else
|
||||
sleep(0.02)
|
||||
end
|
||||
if input ~= beforeInput or cursorPos ~= beforeCursor then contentChanged = true end
|
||||
local curBlink = ((math.floor(syscall.getUptime()/500)%2)==0)
|
||||
if curBlink~=blinkState then blinkState=curBlink;dirty=true end
|
||||
if dirty then redraw();dirty=false end
|
||||
if dirty then
|
||||
if contentChanged then redraw() else redrawCursorOnly() end
|
||||
dirty=false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1245,6 +1347,7 @@ while true do
|
||||
table.insert(commandHistory, command)
|
||||
end
|
||||
runCommand(command)
|
||||
invalidateCaches()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user