mirror of
https://github.com/20kdc/OC-KittenOS.git
synced 2024-11-27 12:58:05 +11:00
Optimize Icecap Nexus
The things I have to destroy, the joy in it! For all I remove the more I save, the better it is! Perfection is when there is nothing to take away, and I revel in this task.
This commit is contained in:
parent
a22ac86b2d
commit
921425ada4
@ -26,72 +26,41 @@ local function addOnReg(p, f)
|
|||||||
table.insert(onReg[p], f)
|
table.insert(onReg[p], f)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function resumeWF(...)
|
|
||||||
local ok, e = coroutine.resume(...)
|
|
||||||
if not ok then
|
|
||||||
e = tostring(e)
|
|
||||||
neo.emergency(e)
|
|
||||||
nexus.startDialog(e, "ice")
|
|
||||||
end
|
|
||||||
return ok, e
|
|
||||||
end
|
|
||||||
|
|
||||||
nexus = {
|
nexus = {
|
||||||
createNexusThread = function (f, ...)
|
create = function (w, h, t, c)
|
||||||
local t = coroutine.create(f)
|
|
||||||
local ok, cbi = resumeWF(t, ...)
|
|
||||||
if not ok then return end
|
|
||||||
local early = neo.requestAccess("x.neo.pub.window", theEventHandler)
|
|
||||||
if early then
|
|
||||||
local r = onReg["x.neo.pub.window"]
|
|
||||||
-- r should not be nil here
|
|
||||||
onReg["x.neo.pub.window"] = nil
|
|
||||||
for k, v in ipairs(r) do
|
|
||||||
v()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return function ()
|
|
||||||
local r = onReg["x.neo.pub.window"]
|
|
||||||
if not r then return end
|
|
||||||
for k, v in ipairs(r) do
|
|
||||||
if v == cbi then
|
|
||||||
table.remove(r, k)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
create = function (w, h, t)
|
|
||||||
local thr = coroutine.running()
|
|
||||||
local function cb()
|
local function cb()
|
||||||
coroutine.resume(thr, neo.requestAccess("x.neo.pub.window"))
|
local e = neo.requestAccess("x.neo.pub.window", theEventHandler)
|
||||||
|
if e then
|
||||||
|
if onReg["x.neo.pub.window"] then
|
||||||
|
neo.emergency("icecap nexus prereg issue")
|
||||||
|
theEventHandler("k.registration", "x.neo.pub.window")
|
||||||
end
|
end
|
||||||
|
local dw = e(w, h, t)
|
||||||
|
c(dw)
|
||||||
|
everestWindows[dw.id] = function (...)
|
||||||
|
return c(dw, ...)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not cb() then
|
||||||
addOnReg("x.neo.pub.window", cb)
|
addOnReg("x.neo.pub.window", cb)
|
||||||
local everest = coroutine.yield(cb)
|
end
|
||||||
local dw = everest(w, h, title)
|
|
||||||
everestWindows[dw.id] = thr
|
|
||||||
return dw
|
return dw
|
||||||
end,
|
end,
|
||||||
|
windows = everestWindows,
|
||||||
startDialog = function (tx, ti)
|
startDialog = function (tx, ti)
|
||||||
local fmt = require("fmttext")
|
local txl = require("fmttext").fmtText(unicode.safeTextFormat(tx), 40)
|
||||||
local txl = fmt.fmtText(unicode.safeTextFormat(tx), 40)
|
nexus.create(40, #txl, ti, function (w, ev, a)
|
||||||
fmt = nil
|
|
||||||
nexus.createNexusThread(function ()
|
|
||||||
local w = nexus.create(40, #txl, ti)
|
|
||||||
while true do
|
|
||||||
local ev, a = coroutine.yield()
|
|
||||||
if ev == "line" then
|
if ev == "line" then
|
||||||
w.span(1, a, txl[a], 0xFFFFFF, 0)
|
if not pcall(w.span, 1, a, txl[a], 0xFFFFFF, 0) then
|
||||||
|
everestWindows[dw.id] = nil
|
||||||
|
end
|
||||||
elseif ev == "close" then
|
elseif ev == "close" then
|
||||||
w.close()
|
w.close()
|
||||||
return
|
everestWindows[dw.id] = nil
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end,
|
|
||||||
close = function (wnd)
|
|
||||||
wnd.close()
|
|
||||||
everestWindows[wnd.id] = nil
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,10 +313,7 @@ function theEventHandler(...)
|
|||||||
elseif ev[1] == "x.neo.pub.window" then
|
elseif ev[1] == "x.neo.pub.window" then
|
||||||
local v = everestWindows[ev[2]]
|
local v = everestWindows[ev[2]]
|
||||||
if v then
|
if v then
|
||||||
resumeWF(v, table.unpack(ev, 3))
|
v(table.unpack(ev, 3))
|
||||||
if coroutine.status(v) == "dead" then
|
|
||||||
everestWindows[ev[2]] = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
-- just don't bother with proper indent here
|
-- just don't bother with proper indent here
|
||||||
return function (event, nexus, retFunc, fs, pkg, mode)
|
return function (event, nexus, retFunc, fs, pkg, mode)
|
||||||
|
|
||||||
local fmt = require("fmttext")
|
local fmt = require("fmttext")
|
||||||
local class = "manage"
|
local class = "manage"
|
||||||
if mode ~= nil then
|
if mode ~= nil then
|
||||||
@ -13,36 +14,19 @@ if mode ~= nil then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local prepareNode
|
-- State
|
||||||
|
local w, h, ctrl = 30, 8, false
|
||||||
|
local l, selection, unknownTx
|
||||||
|
local node, wnd
|
||||||
|
|
||||||
local ccb = nil
|
|
||||||
local function cb(...)
|
local function prepareNode(n)
|
||||||
local res, e = pcall(ccb, ...)
|
node = n
|
||||||
if not res then
|
l = node.list()
|
||||||
prepareNode({
|
selection, unknownTx = 1, ""
|
||||||
name = "F.M. Error",
|
wnd.setSize(w, h)
|
||||||
list = function ()
|
|
||||||
local l = {}
|
|
||||||
for k, v in ipairs(fmt.fmtText(unicode.safeTextFormat(e), 25)) do
|
|
||||||
l[k] = {v, function () return true end}
|
|
||||||
end
|
|
||||||
return l
|
|
||||||
end,
|
|
||||||
unknownAvailable = false,
|
|
||||||
selectUnknown = function (text) end
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local w, h = 30, 8
|
|
||||||
|
|
||||||
local function prepareNodeI(node)
|
|
||||||
local l = node.list()
|
|
||||||
-- Local State
|
|
||||||
-- Selection. Having this equal to #l + 1 means typing area ('unknown')
|
|
||||||
local selection = 1
|
|
||||||
local unknownTx = ""
|
|
||||||
--
|
|
||||||
local function format(a)
|
local function format(a)
|
||||||
if a <= 1 then
|
if a <= 1 then
|
||||||
return false, fmt.pad(unicode.safeTextFormat(node.name), w, true, true)
|
return false, fmt.pad(unicode.safeTextFormat(node.name), w, true, true)
|
||||||
@ -58,7 +42,8 @@ local function prepareNodeI(node)
|
|||||||
end
|
end
|
||||||
return selection == idx, utx
|
return selection == idx, utx
|
||||||
end
|
end
|
||||||
local function updateLine(wnd, a)
|
|
||||||
|
local function updateLine(a)
|
||||||
local colA, colB = 0xFFFFFF, 0
|
local colA, colB = 0xFFFFFF, 0
|
||||||
local sel, text = format(a)
|
local sel, text = format(a)
|
||||||
if sel then
|
if sel then
|
||||||
@ -66,13 +51,14 @@ local function prepareNodeI(node)
|
|||||||
end
|
end
|
||||||
wnd.span(1, a, text, colA, colB)
|
wnd.span(1, a, text, colA, colB)
|
||||||
end
|
end
|
||||||
local function flush(wnd)
|
|
||||||
|
local function flush()
|
||||||
for i = 1, h do
|
for i = 1, h do
|
||||||
updateLine(wnd, i)
|
updateLine(i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local ctrl = false
|
|
||||||
local function key(wnd, ka, kc, down)
|
local function key(ka, kc, down)
|
||||||
if kc == 29 then
|
if kc == 29 then
|
||||||
ctrl = down
|
ctrl = down
|
||||||
end
|
end
|
||||||
@ -91,8 +77,7 @@ local function prepareNodeI(node)
|
|||||||
end
|
end
|
||||||
wnd.setSize(w, h)
|
wnd.setSize(w, h)
|
||||||
return
|
return
|
||||||
end
|
elseif (ka == 9) or (kc == 208) then
|
||||||
if (ka == 9) or (kc == 208) then
|
|
||||||
local lo = selection
|
local lo = selection
|
||||||
selection = selection + 1
|
selection = selection + 1
|
||||||
local max = #l
|
local max = #l
|
||||||
@ -102,10 +87,7 @@ local function prepareNodeI(node)
|
|||||||
if selection > max then
|
if selection > max then
|
||||||
selection = 1
|
selection = 1
|
||||||
end
|
end
|
||||||
flush(wnd)
|
elseif kc == 200 then
|
||||||
return
|
|
||||||
end
|
|
||||||
if kc == 200 then
|
|
||||||
local lo = selection
|
local lo = selection
|
||||||
selection = selection - 1
|
selection = selection - 1
|
||||||
local max = #l
|
local max = #l
|
||||||
@ -115,10 +97,7 @@ local function prepareNodeI(node)
|
|||||||
if selection == 0 then
|
if selection == 0 then
|
||||||
selection = max
|
selection = max
|
||||||
end
|
end
|
||||||
flush(wnd)
|
elseif ka == 13 then
|
||||||
return
|
|
||||||
end
|
|
||||||
if ka == 13 then
|
|
||||||
local aResult, res
|
local aResult, res
|
||||||
if selection ~= #l + 1 then
|
if selection ~= #l + 1 then
|
||||||
aResult, res = l[selection][2]()
|
aResult, res = l[selection][2]()
|
||||||
@ -127,77 +106,77 @@ local function prepareNodeI(node)
|
|||||||
end
|
end
|
||||||
if aResult then
|
if aResult then
|
||||||
retFunc(res)
|
retFunc(res)
|
||||||
nexus.close(wnd)
|
nexus.windows[wnd.id] = nil
|
||||||
|
wnd.close()
|
||||||
else
|
else
|
||||||
prepareNode(res)
|
prepareNode(res)
|
||||||
end
|
end
|
||||||
return
|
elseif selection == #l + 1 then
|
||||||
end
|
|
||||||
if selection == #l + 1 then
|
|
||||||
if ka == 8 then
|
if ka == 8 then
|
||||||
unknownTx = unicode.sub(unknownTx, 1, unicode.len(unknownTx) - 1)
|
unknownTx = unicode.sub(unknownTx, 1, unicode.len(unknownTx) - 1)
|
||||||
flush(wnd)
|
elseif ka ~= 0 then
|
||||||
return
|
|
||||||
end
|
|
||||||
if ka ~= 0 then
|
|
||||||
unknownTx = unknownTx .. unicode.char(ka)
|
unknownTx = unknownTx .. unicode.char(ka)
|
||||||
flush(wnd)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
flush()
|
||||||
end
|
end
|
||||||
return w, h, function (wnd, evt, a, b, c)
|
|
||||||
if evt == "key" then
|
local function key2(...)
|
||||||
key(wnd, a, b, c)
|
local res, e = pcall(key, ...)
|
||||||
|
if not res then
|
||||||
|
prepareNode({
|
||||||
|
name = "F.M. Error",
|
||||||
|
list = function ()
|
||||||
|
local l = {}
|
||||||
|
for k, v in ipairs(fmt.fmtText(unicode.safeTextFormat(e), w)) do
|
||||||
|
l[k] = {v, function () return true end}
|
||||||
end
|
end
|
||||||
if evt == "touch" then
|
return l
|
||||||
|
end,
|
||||||
|
unknownAvailable = false,
|
||||||
|
selectUnknown = function (text) end
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
nexus.create(w, h, class .. " " .. pkg, function (w, ev, a, b, c)
|
||||||
|
if not wnd then
|
||||||
|
wnd = w
|
||||||
|
prepareNode(require("sys-filevfs")(fs, mode))
|
||||||
|
end
|
||||||
|
if ev == "key" then
|
||||||
|
key2(a, b, c)
|
||||||
|
end
|
||||||
|
if ev == "touch" then
|
||||||
local ns = b + math.max(1, selection - 3) - 2
|
local ns = b + math.max(1, selection - 3) - 2
|
||||||
local max = #l
|
local max = #l
|
||||||
if node.unknownAvailable then
|
if node.unknownAvailable then
|
||||||
max = max + 1
|
max = max + 1
|
||||||
end
|
end
|
||||||
if ns == selection and ((selection ~= #l + 1) or (a <= 4)) then
|
if ns == selection and ((selection ~= #l + 1) or (a <= 4)) then
|
||||||
key(wnd, 13, 0, true)
|
key2(13, 0, true)
|
||||||
else
|
else
|
||||||
selection = math.min(math.max(1, ns), max)
|
selection = math.min(math.max(1, ns), max)
|
||||||
flush(wnd)
|
flush()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if evt == "line" then
|
if ev == "line" then
|
||||||
updateLine(wnd, a)
|
updateLine(a)
|
||||||
end
|
end
|
||||||
if evt == "close" then
|
if ev == "close" then
|
||||||
retFunc(nil)
|
retFunc(nil)
|
||||||
nexus.close(wnd)
|
nexus.windows[wnd.id] = nil
|
||||||
end
|
wnd.close()
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local text = class .. " " .. pkg
|
|
||||||
local window
|
|
||||||
|
|
||||||
function prepareNode(node)
|
|
||||||
local w, h, c = prepareNodeI(node)
|
|
||||||
ccb = c
|
|
||||||
window.setSize(w, h)
|
|
||||||
end
|
|
||||||
|
|
||||||
local closer = nexus.createNexusThread(function ()
|
|
||||||
window = nexus.create(25, 10, text)
|
|
||||||
prepareNode(require("sys-filevfs")(fs, mode))
|
|
||||||
while window do
|
|
||||||
cb(window, coroutine.yield())
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
if not closer then
|
|
||||||
retFunc()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
return function ()
|
return function ()
|
||||||
retFunc()
|
retFunc()
|
||||||
closer()
|
closer()
|
||||||
if window then
|
if wnd then
|
||||||
nexus.close(window)
|
nexus.windows[wnd.id] = nil
|
||||||
window = nil
|
wnd.close()
|
||||||
|
wnd = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -88,10 +88,10 @@ function getFsNode(fs, parent, fsc, path, mode)
|
|||||||
return nil, parent
|
return nil, parent
|
||||||
end}
|
end}
|
||||||
for k, v in ipairs(fsc.list(path)) do
|
for k, v in ipairs(fsc.list(path)) do
|
||||||
local nm = "[F] " .. v
|
local nm = "F: " .. v
|
||||||
local fp = path .. v
|
local fp = path .. v
|
||||||
if fsc.isDirectory(fp) then
|
if fsc.isDirectory(fp) then
|
||||||
nm = "[D] " .. v
|
nm = "D: " .. v
|
||||||
end
|
end
|
||||||
n[k + 1] = {nm, function () return nil, getFsNode(fs, t, fsc, fp, mode) end}
|
n[k + 1] = {nm, function () return nil, getFsNode(fs, t, fsc, fp, mode) end}
|
||||||
end
|
end
|
||||||
|
@ -56,31 +56,31 @@ return function (nexus, settings, pkg, pid, perm, rsp, matchesSvc)
|
|||||||
local buttons = {
|
local buttons = {
|
||||||
{"<No>", function (w)
|
{"<No>", function (w)
|
||||||
rsp(false)
|
rsp(false)
|
||||||
nexus.close(w)
|
nexus.windows[w.id] = nil
|
||||||
|
w.close()
|
||||||
end},
|
end},
|
||||||
{"<Always>", function (w)
|
{"<Always>", function (w)
|
||||||
if settings then
|
if settings then
|
||||||
settings.setSetting("perm|" .. pkg .. "|" .. perm, "allow")
|
settings.setSetting("perm|" .. pkg .. "|" .. perm, "allow")
|
||||||
end
|
end
|
||||||
rsp(true)
|
rsp(true)
|
||||||
nexus.close(w)
|
nexus.windows[w.id] = nil
|
||||||
|
w.close()
|
||||||
end},
|
end},
|
||||||
{"<Yes>", function (w)
|
{"<Yes>", function (w)
|
||||||
rsp(true)
|
rsp(true)
|
||||||
nexus.close(w)
|
nexus.windows[w.id] = nil
|
||||||
|
w.close()
|
||||||
end}
|
end}
|
||||||
}
|
}
|
||||||
nexus.createNexusThread(function ()
|
|
||||||
local window = nexus.create(totalW, #fmt, "security")
|
|
||||||
local cButton = 0
|
local cButton = 0
|
||||||
local ev, a, b, c
|
nexus.create(totalW, #fmt, "security", function (window, ev, a, b, c)
|
||||||
while true do
|
while ev do
|
||||||
if not ev then
|
|
||||||
ev, a, b, c = coroutine.yield()
|
|
||||||
end
|
|
||||||
if ev == "line" or ev == "touch" then
|
if ev == "line" or ev == "touch" then
|
||||||
local cor = b
|
local cor = b
|
||||||
if ev == "line" then
|
local iev = ev
|
||||||
|
ev = nil
|
||||||
|
if iev == "line" then
|
||||||
cor = a
|
cor = a
|
||||||
if fmt[a] then
|
if fmt[a] then
|
||||||
window.span(1, a, fmt[a], 0xFFFFFF, 0)
|
window.span(1, a, fmt[a], 0xFFFFFF, 0)
|
||||||
@ -89,7 +89,7 @@ return function (nexus, settings, pkg, pid, perm, rsp, matchesSvc)
|
|||||||
if cor == #fmt then
|
if cor == #fmt then
|
||||||
local x = 1
|
local x = 1
|
||||||
for k, v in ipairs(buttons) do
|
for k, v in ipairs(buttons) do
|
||||||
if ev == "line" then
|
if iev == "line" then
|
||||||
if k ~= cButton + 1 then
|
if k ~= cButton + 1 then
|
||||||
window.span(x, a, v[1], 0xFFFFFF, 0)
|
window.span(x, a, v[1], 0xFFFFFF, 0)
|
||||||
else
|
else
|
||||||
@ -108,10 +108,10 @@ return function (nexus, settings, pkg, pid, perm, rsp, matchesSvc)
|
|||||||
end
|
end
|
||||||
elseif ev == "close" then
|
elseif ev == "close" then
|
||||||
rsp(false)
|
rsp(false)
|
||||||
nexus.close(window)
|
nexus.windows[w.id] = nil
|
||||||
return
|
w.close()
|
||||||
end
|
ev = nil
|
||||||
if ev == "key" then
|
elseif ev == "key" then
|
||||||
if c and (a == 9 or b == 205) then
|
if c and (a == 9 or b == 205) then
|
||||||
cButton = (cButton + 1) % #buttons
|
cButton = (cButton + 1) % #buttons
|
||||||
ev = "line"
|
ev = "line"
|
||||||
|
Loading…
Reference in New Issue
Block a user