r8: Yet another release for a single feature request

This isn't getting pushed until AmandaC's tested it.
I'm not sure this is such a good idea, anyway ; if it's for load/save
 workflow improvements, wouldn't it be better to have a file access method
 that allows for file re-opening?
That said, there's a limit to *that* before you just have to say,
 "Just use /data/".
This commit is contained in:
20kdc 2018-12-23 23:51:30 +00:00
parent 375995c2d3
commit 0d9583fcff
11 changed files with 80 additions and 67 deletions

View File

@ -3,7 +3,7 @@
return { return {
["neo"] = { ["neo"] = {
desc = "KittenOS NEO Kernel & Base Libs", desc = "KittenOS NEO Kernel & Base Libs",
v = 5, v = 8,
deps = { deps = {
}, },
dirs = { dirs = {
@ -67,7 +67,7 @@ return {
}, },
["neo-icecap"] = { ["neo-icecap"] = {
desc = "KittenOS NEO / Icecap", desc = "KittenOS NEO / Icecap",
v = 7, v = 8,
deps = { deps = {
"neo" "neo"
}, },
@ -125,7 +125,7 @@ return {
}, },
["neo-logo"] = { ["neo-logo"] = {
desc = "KittenOS NEO Logo (data)", desc = "KittenOS NEO Logo (data)",
v = 6, v = 8,
deps = { deps = {
}, },
dirs = { dirs = {

View File

@ -24,7 +24,7 @@ return {
}, },
["neo-docs"] = { ["neo-docs"] = {
desc = "KittenOS NEO system documentation", desc = "KittenOS NEO system documentation",
v = 5, v = 8,
deps = { deps = {
"zzz-license-pd" "zzz-license-pd"
}, },

View File

@ -109,17 +109,20 @@ donkonitDFProvider(function (pkg, pid, sendSig)
end end
end end
return { return {
showFileDialogAsync = function (forWrite) showFileDialogAsync = function (forWrite, defName)
if not rawequal(forWrite, nil) then if not rawequal(forWrite, nil) then
require("sys-filewrap").ensureMode(forWrite) require("sys-filewrap").ensureMode(forWrite)
end end
if not rawequal(defName, nil) then
defName = tostring(defName)
end
-- Not hooked into the event API, so can't safely interfere -- Not hooked into the event API, so can't safely interfere
-- Thus, this is async and uses a return event. -- Thus, this is async and uses a return event.
local tag = {} local tag = {}
neo.scheduleTimer(0) neo.scheduleTimer(0)
table.insert(todo, function () table.insert(todo, function ()
-- sys-filedialog is yet another "library to control memory usage". -- sys-filedialog is yet another "library to control memory usage".
local closer = require("sys-filedialog")(event, nexus, function (res) openHandles[tag] = nil sendSig("filedialog", tag, res) end, neo.requireAccess("c.filesystem", "file managers"), pkg, forWrite) local closer = require("sys-filedialog")(event, nexus, function (res) openHandles[tag] = nil sendSig("filedialog", tag, res) end, neo.requireAccess("c.filesystem", "file managers"), pkg, forWrite, defName)
openHandles[tag] = closer openHandles[tag] = closer
end) end)
return tag return tag

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -25,7 +25,7 @@ newNeoux = function (event, neo)
end end
end) end)
local neoux = {} local neoux = {}
neoux.fileDialog = function (forWrite, callback) neoux.fileDialog = function (forWrite, callback, dfn)
local sync = false local sync = false
local rtt = nil local rtt = nil
if not callback then if not callback then
@ -35,7 +35,7 @@ newNeoux = function (event, neo)
rtt = rt rtt = rt
end end
end end
local tag = neo.requireAccess("x.neo.pub.base", "filedialog").showFileDialogAsync(forWrite) local tag = neo.requireAccess("x.neo.pub.base", "filedialog").showFileDialogAsync(forWrite, dfn)
local f local f
f = function (_, fd, tg, re) f = function (_, fd, tg, re)
if fd == "filedialog" then if fd == "filedialog" then

View File

@ -2,7 +2,7 @@
-- No warranty is provided, implied or otherwise. -- No warranty is provided, implied or otherwise.
-- 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, defName)
local fmt = require("fmttext") local fmt = require("fmttext")
local class = "manage" local class = "manage"
@ -141,7 +141,7 @@ end
nexus.create(w, h, class .. " " .. pkg, function (w, ev, a, b, c) nexus.create(w, h, class .. " " .. pkg, function (w, ev, a, b, c)
if not wnd then if not wnd then
wnd = w wnd = w
prepareNode(require("sys-filevfs")(fs, mode)) prepareNode(require("sys-filevfs")(fs, mode, defName))
end end
if ev == "key" then if ev == "key" then
key2(a, b, c) key2(a, b, c)

View File

@ -16,12 +16,12 @@ end
local getFsNode, getRoot local getFsNode, getRoot
local setupCopyNode local setupCopyNode
function setupCopyNode(parent, myRoot, op, complete, impliedName) function setupCopyNode(parent, myRoot, op, complete)
local function handleResult(aRes, res) local function handleResult(aRes, res)
if aRes then if aRes then
return complete(res, true) return complete(res, true)
else else
return nil, setupCopyNode(parent, res, op, complete, impliedName) return nil, setupCopyNode(parent, res, op, complete)
end end
end end
return { return {
@ -32,11 +32,6 @@ function setupCopyNode(parent, myRoot, op, complete, impliedName)
complete(nil, false) complete(nil, false)
return false, parent return false, parent
end}) end})
if impliedName and myRoot.unknownAvailable then
table.insert(l, {"Implied: " .. impliedName, function ()
return handleResult(myRoot.selectUnknown(impliedName))
end})
end
for _, v in ipairs(myRoot.list()) do for _, v in ipairs(myRoot.list()) do
table.insert(l, {v[1], function () table.insert(l, {v[1], function ()
return handleResult(v[2]()) return handleResult(v[2]())
@ -54,7 +49,7 @@ local function setupCopyVirtualEnvironment(fs, parent, fwrap, impliedName)
if not fwrap then if not fwrap then
return false, dialog("Could not open source", parent) return false, dialog("Could not open source", parent)
end end
local myRoot = getRoot(fs, true) local myRoot = getRoot(fs, true, impliedName)
-- Setup wrapping node -- Setup wrapping node
return setupCopyNode(parent, myRoot, "Copy", function (fwrap2, intent) return setupCopyNode(parent, myRoot, "Copy", function (fwrap2, intent)
if not fwrap2 then if not fwrap2 then
@ -72,14 +67,22 @@ local function setupCopyVirtualEnvironment(fs, parent, fwrap, impliedName)
fwrap.close() fwrap.close()
fwrap2.close() fwrap2.close()
return false, dialog("Completed copy.", parent) return false, dialog("Completed copy.", parent)
end, impliedName) end)
end end
function getFsNode(fs, parent, fsc, path, mode) function getFsNode(fs, parent, fsc, path, mode, impliedName)
local va = fsc.address:sub(1, 4) local va = fsc.address:sub(1, 4)
local fscrw = not fsc.isReadOnly() local fscrw = not fsc.isReadOnly()
local dir = path:sub(#path, #path) == "/" local dir = path:sub(#path, #path) == "/"
local confirmedDel = false local confirmedDel = false
local t local t
local function selectUnknown(text)
-- Relies on text being nil if used in leaf node
local rt, re = require("sys-filewrap").create(fsc, path .. (text or ""), mode)
if not rt then
return false, dialog("Open Error: " .. tostring(re), parent)
end
return true, rt
end
t = { t = {
name = ((dir and "DIR: ") or "FILE: ") .. va .. path, name = ((dir and "DIR: ") or "FILE: ") .. va .. path,
list = function () list = function ()
@ -94,18 +97,9 @@ function getFsNode(fs, parent, fsc, path, mode)
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, impliedName) end}
end end
end end
if not dir then
table.insert(n, {"Copy", function ()
local rt, re = require("sys-filewrap").create(fsc, path, false)
if not rt then
return false, dialog("Open Error: " .. tostring(re), parent)
end
return nil, setupCopyVirtualEnvironment(fs, parent, rt, path:match("[^/]*$") or "")
end})
end
if fscrw then if fscrw then
if dir then if dir then
table.insert(n, {"Mk. Directory", function () table.insert(n, {"Mk. Directory", function ()
@ -156,37 +150,38 @@ function getFsNode(fs, parent, fsc, path, mode)
end}) end})
end end
end end
if (fscrw or mode == false) and mode ~= nil then if not dir then
local tx = "Open" table.insert(n, {"Copy", function ()
if mode == true then local rt, re = require("sys-filewrap").create(fsc, path, false)
tx = "Save" if not rt then
elseif mode == "append" then return false, dialog("Open Error: " .. tostring(re), parent)
tx = "Append" end
end return nil, setupCopyVirtualEnvironment(fs, parent, rt, path:match("[^/]*$") or "")
if fscrw or mode == false then end})
table.insert(n, {tx, function () if (fscrw or mode == false) and (mode ~= nil) then
local rt, re = require("sys-filewrap").create(fsc, path, mode) local tx = "Open"
if not rt then if mode == true then
return false, dialog("Open Error: " .. tostring(re), parent) tx = "Save (Overwrite)"
end elseif mode == "append" then
return true, rt tx = "Append"
end}) end
if fscrw or mode == false then
table.insert(n, {tx, selectUnknown})
end
end end
elseif impliedName then
table.insert(n, {"Implied: " .. impliedName, function ()
return selectUnknown(impliedName)
end})
end end
return n return n
end, end,
unknownAvailable = dir and (mode ~= nil) and ((mode == false) or fscrw), unknownAvailable = dir and (mode ~= nil) and ((mode == false) or fscrw),
selectUnknown = function (text) selectUnknown = selectUnknown
local rt, re = require("sys-filewrap").create(fsc, path .. text, mode)
if not rt then
return false, dialog("Open Error: " .. tostring(re), parent)
end
return true, rt
end
} }
return t return t
end end
function getRoot(fs, mode) function getRoot(fs, mode, defName)
local t local t
t = { t = {
name = "DRVS:", name = "DRVS:",
@ -210,7 +205,7 @@ function getRoot(fs, mode)
id = "RW " .. amount .. "% " .. mb .. "M " .. id id = "RW " .. amount .. "% " .. mb .. "M " .. id
end end
table.insert(l, {fsi.address:sub(1, 4) .. " " .. id, function () table.insert(l, {fsi.address:sub(1, 4) .. " " .. id, function ()
return nil, getFsNode(fs, t, fsi, "/", mode) return nil, getFsNode(fs, t, fsi, "/", mode, defName)
end}) end})
end end
return l return l

View File

@ -34,8 +34,12 @@ while blk ~= "" do
break break
end end
local pm = p - 1 local pm = p - 1
bestData = string.char(128 + lm, math.floor(pm / 256), pm % 256) local thirdByte = pm % 256
bestRes = pfx -- anti ']'-corruption helper
if thirdByte ~= 93 then
bestData = string.char(128 + lm, math.floor(pm / 256), thirdByte)
bestRes = pfx
end
end end
-- ok, encode! -- ok, encode!
io.write(bestData) io.write(bestData)

View File

@ -15,10 +15,12 @@ The mode you give to it can be one of
true: Write "wb" true: Write "wb"
"append": Append "ab" "append": Append "ab"
May have some readability May have some readability
propertiues - just in properties - just in
case, I've added 'read', case, I've added 'read',
but don't get your hopes but don't get your hopes
up... up...
"access": Like read, but can be
re-opened for write.
It returns two things - a table, that It returns two things - a table, that
being the file object, and the being the file object, and the
@ -37,7 +39,9 @@ The possible functions are:
[aw] write(data): Writes to the [aw] write(data): Writes to the
file. file.
[arw] read(data): Reads from the [arw] read(data): Reads from the
file. file. data is the byte count.
However, "*a" is valid here.
Other string-based options are not.
NOTE: Some of these may not actually NOTE: Some of these may not actually
work. They're just there as more or work. They're just there as more or

View File

@ -33,16 +33,19 @@ The most reliable reference on the
Main functions: Main functions:
fileDialog(mode[, callback]): neoux.fileDialog(mode, [callback],
[dfn]):
Creates a file dialog, returning a Creates a file dialog, returning a
file wrapper (see ul-fwrap) on file wrapper (see ul-fwrap) on
success, or nil on failure. success, or nil on failure.
If a callback is given, then nil is If callback isn't nil, then nil is
always returned immediately, and always returned immediately, and
the callback is called when the the callback is called with the
dialog has shown. result when the dialog is closed.
mode is the mode used for the file, mode is the mode used for the file,
so see ul-fwrap for values. so see ul-fwrap for values.
dfn is, if not nil, the default
'implied' filename (as with Copy).
neoux.create(w, h, title, callback): neoux.create(w, h, title, callback):
Creates a window, Creates a window,

View File

@ -57,11 +57,15 @@ Paths for the IO parts of this API
the standard KittenOS NEO path the standard KittenOS NEO path
safety rules in the kernel. safety rules in the kernel.
showFileDialogAsync(mode): Shows a showFileDialogAsync(mode, dfn):
filedialog with a given filemode, Shows a filedialog with a given
or nil for "none". Returns a new, filemode, or nil for "none".
empty table as a "tag", and emits a Returns a new, empty table as a
"filedialog" event on completion. "tag", and emits a "filedialog"
event on completion.
dfn meanwhile adds an 'Implied'
button for reasonable default file
names.
myApi: A string such as "svc.abc" myApi: A string such as "svc.abc"
for the program svc-abc, used for for the program svc-abc, used for