1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-11-23 19:08:05 +11:00

More optimizations and fixes - R2 release candidate???

It's clinging to within an inch of its life, but the 192K save/load is working,
 now I've cleaned up the critical path.

Any requests that'll bloat critical APIs are going to have to be terminated,
 though, because this is getting out of hand.
This commit is contained in:
20kdc 2018-04-25 23:58:31 +01:00
parent 921425ada4
commit 5004f15c2d
4 changed files with 70 additions and 74 deletions

View File

@ -26,8 +26,9 @@ local lines = {
-- and then after an action occurs switches to "append" until *any cursor action is performed*. -- and then after an action occurs switches to "append" until *any cursor action is performed*.
-- The way I have things setup is that you perform J then K(repeat) *instead*, which means you have to explicitly say "destroy current clipboard". -- The way I have things setup is that you perform J then K(repeat) *instead*, which means you have to explicitly say "destroy current clipboard".
local event = require("event")(neo)
local clipsrc = neo.requireAccess("x.neo.pub.globals", "clipboard") local clipsrc = neo.requireAccess("x.neo.pub.globals", "clipboard")
local windows = neo.requireAccess("x.neo.pub.window", "windows")
local files = neo.requireAccess("x.neo.pub.base", "files").showFileDialogAsync
local cursorX = 1 local cursorX = 1
local cursorY = math.ceil(#lines / 2) local cursorY = math.ceil(#lines / 2)
@ -36,8 +37,8 @@ local ctrlFlag = false
local dialogLock = false local dialogLock = false
local appendFlag = false local appendFlag = false
local sW, sH = 37, #lines + 2 local sW, sH = 37, #lines + 2
local windows = neo.requestAccess("x.neo.pub.window")
local window = windows(sW, sH) local window = windows(sW, sH)
local filedialog = nil
local flush local flush
local function splitCur() local function splitCur()
@ -59,11 +60,7 @@ end
local cbs = {} local cbs = {}
local function fileDialog(writing, callback) local function fileDialog(writing, callback)
local tag = neo.requestAccess("x.neo.pub.base").showFileDialogAsync(writing) filedialog = function (res)
local f
function f(_, evt, tag2, res)
if evt == "filedialog" then
if tag == tag2 then
local ok, e = pcall(callback, res) local ok, e = pcall(callback, res)
if not ok then if not ok then
e = unicode.safeTextFormat(tostring(e)) e = unicode.safeTextFormat(tostring(e))
@ -74,11 +71,8 @@ local function fileDialog(writing, callback)
e e
} }
end end
event.ignore(f)
end end
end files(writing)
end
event.listen("x.neo.pub.base", f)
end end
-- Save/Load -- Save/Load
@ -86,14 +80,19 @@ local function startSave()
dialogLock = true dialogLock = true
fileDialog(true, function (res) fileDialog(true, function (res)
dialogLock = false dialogLock = false
local x = ""
if res then if res then
for k, v in ipairs(lines) do for k, v in ipairs(lines) do
if k ~= 1 then if k ~= 1 then
res.write("\n" .. v) x = x .. "\n"
else end
res.write(v) x = x .. v
while #x >= neo.readBufSize do
res.write(x:sub(1, neo.readBufSize))
x = x:sub(neo.readBufSize + 1)
end end
end end
res.write(x)
res.close() res.close()
end end
end) end)
@ -107,7 +106,7 @@ local function startLoad()
lines = {} lines = {}
local lb = "" local lb = ""
while true do while true do
local l = res.read(64) local l = res.read(neo.readBufSize)
if not l then if not l then
table.insert(lines, lb) table.insert(lines, lb)
cursorX = 1 cursorX = 1
@ -196,7 +195,7 @@ local function putLetter(ch)
lines[cursorY] = a .. b lines[cursorY] = a .. b
cursorX = unicode.len(a) + 1 cursorX = unicode.len(a) + 1
end end
local function ev_key(ka, kc, down) local function key(ka, kc, down)
if dialogLock then if dialogLock then
return false return false
end end
@ -363,7 +362,44 @@ local function ev_key(ka, kc, down)
return false return false
end end
local function ev_clipboard(t) flush = function ()
for i = 1, sH do
window.span(1, i, getline(i), 0xFFFFFF, 0)
end
end
neo.scheduleTimer(os.uptime() + 0.5)
while true do
local e = {coroutine.yield()}
if e[1] == "k.timer" then
cFlash = not cFlash
local csY = math.ceil(sH / 2)
window.span(1, csY, getline(csY), 0xFFFFFF, 0)
neo.scheduleTimer(os.uptime() + 0.5)
elseif e[1] == "x.neo.pub.window" then
if e[2] == window.id then
if e[3] == "line" then
window.span(1, e[4], getline(e[4]), 0xFFFFFF, 0)
elseif filedialog then
elseif e[3] == "touch" then
-- reverse:
--local rY = (y + cursorY) - math.ceil(sH / 2)
local csY = math.ceil(sH / 2)
local nY = math.max(1, math.min(#lines, (math.floor(e[5]) - csY) + cursorY))
cursorY = nY
clampCursorX()
flush()
elseif e[3] == "key" then
if key(e[4], e[5], e[6]) then
flush()
end
elseif e[3] == "focus" then
ctrlFlag = false
elseif e[3] == "close" then
return
elseif e[3] == "clipboard" then
local t = e[4]
for i = 1, unicode.len(t) do for i = 1, unicode.len(t) do
local c = unicode.sub(t, i, i) local c = unicode.sub(t, i, i)
if c ~= "\r" then if c ~= "\r" then
@ -373,63 +409,18 @@ local function ev_clipboard(t)
putLetter(c) putLetter(c)
end end
end end
end
flush = function ()
for i = 1, sH do
window.span(1, i, getline(i), 0xFFFFFF, 0)
end
end
local flash
flash = function ()
cFlash = not cFlash
-- reverse:
--local rY = (y + cursorY) - math.ceil(sH / 2)
local csY = math.ceil(sH / 2)
window.span(1, csY, getline(csY), 0xFFFFFF, 0)
event.runAt(os.uptime() + 0.5, flash)
end
event.runAt(os.uptime() + 0.5, flash)
while true do
local e = {event.pull()}
if e[1] == "x.neo.pub.window" then
if e[2] == window.id then
if e[3] == "touch" then
-- reverse:
--local rY = (y + cursorY) - math.ceil(sH / 2)
local csY = math.ceil(sH / 2)
local nY = math.max(1, math.min(#lines, (math.floor(e[5]) - csY) + cursorY))
cursorY = nY
clampCursorX()
flush()
end
if e[3] == "key" then
if ev_key(e[4], e[5], e[6]) then
flush()
end
end
if e[3] == "line" then
window.span(1, e[4], getline(e[4]), 0xFFFFFF, 0)
end
if e[3] == "focus" then
ctrlFlag = false
end
if e[3] == "close" then
return
end
if e[3] == "clipboard" then
ev_clipboard(e[4])
flush() flush()
end end
elseif cbs[e[2]] then elseif cbs[e[2]] then
if e[3] == "line" then if e[3] == "line" then
cbs[e[2]][2](1, 1, cbs[e[2]][3], 0, 0xFFFFFF) cbs[e[2]][2](1, 1, cbs[e[2]][3], 0, 0xFFFFFF)
end elseif e[3] == "close" then
if e[3] == "close" then
cbs[e[2]][1]() cbs[e[2]][1]()
cbs[e[2]] = nil cbs[e[2]] = nil
end end
end end
elseif e[1] == "x.neo.pub.base" and e[2] == "filedialog" and filedialog then
filedialog(e[4])
filedialog = nil
end end
end end

View File

@ -30,7 +30,10 @@ local function doMainWin()
w.reset(doWorking()) w.reset(doWorking())
local nurl = url local nurl = url
local fd = neoux.fileDialog(true) local fd = neoux.fileDialog(true)
if not fd then return end if not fd then
w.reset(doMainWin())
return
end
-- download! -- download!
local req, err = primaryINet.request(nurl) local req, err = primaryINet.request(nurl)
if not req then if not req then

View File

@ -282,6 +282,12 @@ rootAccess.securityPolicy = function (pid, proc, perm, req)
end end
end end
local function dcall(c, ...)
local ok, e = pcall(...)
if not ok then
nexus.startDialog(tostring(e), c .. "err")
end
end
function theEventHandler(...) function theEventHandler(...)
local ev = {...} local ev = {...}
if ev[1] == "k.procdie" then if ev[1] == "k.procdie" then
@ -297,23 +303,20 @@ function theEventHandler(...)
local nt = todo local nt = todo
todo = {} todo = {}
for _, v in ipairs(nt) do for _, v in ipairs(nt) do
local ok, e = pcall(v) dcall("t", v)
if not ok then
nexus.startDialog(tostring(e), "terr")
end
end end
elseif ev[1] == "k.registration" then elseif ev[1] == "k.registration" then
if onReg[ev[2]] then if onReg[ev[2]] then
local tmp = onReg[ev[2]] local tmp = onReg[ev[2]]
onReg[ev[2]] = nil onReg[ev[2]] = nil
for _, v in ipairs(tmp) do for _, v in ipairs(tmp) do
v() dcall("r", v)
end end
end end
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
v(table.unpack(ev, 3)) dcall("w", v, table.unpack(ev, 3))
end end
end end
end end

View File

@ -19,7 +19,6 @@ local w, h, ctrl = 30, 8, false
local l, selection, unknownTx local l, selection, unknownTx
local node, wnd local node, wnd
local function prepareNode(n) local function prepareNode(n)
node = n node = n
l = node.list() l = node.list()
@ -112,7 +111,7 @@ local function key(ka, kc, down)
prepareNode(res) prepareNode(res)
end end
elseif selection == #l + 1 then elseif selection == #l + 1 then
if ka == 8 then if ka == 8 or kc == 211 then
unknownTx = unicode.sub(unknownTx, 1, unicode.len(unknownTx) - 1) unknownTx = unicode.sub(unknownTx, 1, unicode.len(unknownTx) - 1)
elseif ka ~= 0 then elseif ka ~= 0 then
unknownTx = unknownTx .. unicode.char(ka) unknownTx = unknownTx .. unicode.char(ka)