Фиксы ввода вывода и ls валидация параметров

This commit is contained in:
2026-06-14 02:35:17 +03:00
parent 5ef9eb1cb5
commit 14f47767b3
2 changed files with 17 additions and 3 deletions

View File

@@ -108,13 +108,22 @@ reg("ls", function(a)
local opts = {} local opts = {}
for i = 1, #a do for i = 1, #a do
if a[i]:sub(1, 1) == "-" then if a[i]:sub(1, 1) == "-" then
opts[a[i]] = true local opt = a[i]
for j = 2, #opt do
local c = opt:sub(j, j)
if c ~= "a" and c ~= "l" then
error("ls: unknown option '" .. opt .. "'")
end
end
opts[opt] = true
else else
path = resolvePath(a[i]) path = resolvePath(a[i])
end end
end end
local cmdStr = "ls" local cmdStr = "ls"
if #a > 0 then cmdStr = "ls " .. table.concat(a, " ") end for i = 1, #a do
cmdStr = cmdStr .. " " .. tostring(a[i])
end
pendingCmd = { name = "ls", opts = opts, path = path, pendingCmd = { name = "ls", opts = opts, path = path,
prompt = curUser .. " " .. cwd .. "> " .. cmdStr } prompt = curUser .. " " .. cwd .. "> " .. cmdStr }
state = ST_WAIT_FS state = ST_WAIT_FS
@@ -254,6 +263,7 @@ local function handleFSResponse(op, data)
end end
queueLines(lines) queueLines(lines)
out[4] = ""
pendingCmd = nil pendingCmd = nil
state = ST_IDLE state = ST_IDLE
end end

View File

@@ -267,11 +267,15 @@ function upd()
if inp[1] ~= nil then if inp[1] ~= nil then
local req = tostring(inp[1]) local req = tostring(inp[1])
if #req > 0 and req ~= prevReq then if #req == 0 then
prevReq = ""
elseif req ~= prevReq then
prevReq = req prevReq = req
local resp = processReq(req) local resp = processReq(req)
out[1] = resp out[1] = resp
end end
else
prevReq = ""
end end
table.clear(inp) table.clear(inp)