mirror of
https://github.com/20kdc/OC-KittenOS.git
synced 2024-11-27 12:58: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:
parent
921425ada4
commit
5004f15c2d
@ -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,26 +60,19 @@ 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
|
local ok, e = pcall(callback, res)
|
||||||
function f(_, evt, tag2, res)
|
if not ok then
|
||||||
if evt == "filedialog" then
|
e = unicode.safeTextFormat(tostring(e))
|
||||||
if tag == tag2 then
|
local wnd = windows(unicode.len(e), 1, "ERROR")
|
||||||
local ok, e = pcall(callback, res)
|
cbs[wnd.id] = {
|
||||||
if not ok then
|
wnd.close,
|
||||||
e = unicode.safeTextFormat(tostring(e))
|
wnd.span,
|
||||||
local wnd = windows(unicode.len(e), 1, "ERROR")
|
e
|
||||||
cbs[wnd.id] = {
|
}
|
||||||
wnd.close,
|
|
||||||
wnd.span,
|
|
||||||
e
|
|
||||||
}
|
|
||||||
end
|
|
||||||
event.ignore(f)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
event.listen("x.neo.pub.base", f)
|
files(writing)
|
||||||
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,39 +362,27 @@ local function ev_key(ka, kc, down)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function ev_clipboard(t)
|
|
||||||
for i = 1, unicode.len(t) do
|
|
||||||
local c = unicode.sub(t, i, i)
|
|
||||||
if c ~= "\r" then
|
|
||||||
if c == "\n" then
|
|
||||||
c = "\r"
|
|
||||||
end
|
|
||||||
putLetter(c)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
flush = function ()
|
flush = function ()
|
||||||
for i = 1, sH do
|
for i = 1, sH do
|
||||||
window.span(1, i, getline(i), 0xFFFFFF, 0)
|
window.span(1, i, getline(i), 0xFFFFFF, 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local flash
|
|
||||||
flash = function ()
|
neo.scheduleTimer(os.uptime() + 0.5)
|
||||||
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
|
while true do
|
||||||
local e = {event.pull()}
|
local e = {coroutine.yield()}
|
||||||
if e[1] == "x.neo.pub.window" then
|
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[2] == window.id then
|
||||||
if e[3] == "touch" 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:
|
-- reverse:
|
||||||
--local rY = (y + cursorY) - math.ceil(sH / 2)
|
--local rY = (y + cursorY) - math.ceil(sH / 2)
|
||||||
local csY = math.ceil(sH / 2)
|
local csY = math.ceil(sH / 2)
|
||||||
@ -403,33 +390,37 @@ while true do
|
|||||||
cursorY = nY
|
cursorY = nY
|
||||||
clampCursorX()
|
clampCursorX()
|
||||||
flush()
|
flush()
|
||||||
end
|
elseif e[3] == "key" then
|
||||||
if e[3] == "key" then
|
if key(e[4], e[5], e[6]) then
|
||||||
if ev_key(e[4], e[5], e[6]) then
|
|
||||||
flush()
|
flush()
|
||||||
end
|
end
|
||||||
end
|
elseif e[3] == "focus" then
|
||||||
if e[3] == "line" then
|
|
||||||
window.span(1, e[4], getline(e[4]), 0xFFFFFF, 0)
|
|
||||||
end
|
|
||||||
if e[3] == "focus" then
|
|
||||||
ctrlFlag = false
|
ctrlFlag = false
|
||||||
end
|
elseif e[3] == "close" then
|
||||||
if e[3] == "close" then
|
|
||||||
return
|
return
|
||||||
end
|
elseif e[3] == "clipboard" then
|
||||||
if e[3] == "clipboard" then
|
local t = e[4]
|
||||||
ev_clipboard(e[4])
|
for i = 1, unicode.len(t) do
|
||||||
|
local c = unicode.sub(t, i, i)
|
||||||
|
if c ~= "\r" then
|
||||||
|
if c == "\n" then
|
||||||
|
c = "\r"
|
||||||
|
end
|
||||||
|
putLetter(c)
|
||||||
|
end
|
||||||
|
end
|
||||||
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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user