From 0d9583fcff3322fb1140de827a5bb33768c7fe6d Mon Sep 17 00:00:00 2001 From: 20kdc Date: Sun, 23 Dec 2018 23:51:30 +0000 Subject: [PATCH] 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/". --- claw/code-claw.lua | 6 +-- claw/repo-claw.lua | 2 +- code/apps/sys-icecap.lua | 7 ++- code/docs/logo.bmp | Bin 2598 -> 2598 bytes code/libs/neoux.lua | 4 +- code/libs/sys-filedialog.lua | 4 +- code/libs/sys-filevfs.lua | 83 ++++++++++++++++------------------- com2/bdivide.lua | 8 +++- repository/docs/ul-fwrap | 8 +++- repository/docs/ul-neoux | 11 +++-- repository/docs/us-perms | 14 +++--- 11 files changed, 80 insertions(+), 67 deletions(-) diff --git a/claw/code-claw.lua b/claw/code-claw.lua index ec2697b..3c603d5 100644 --- a/claw/code-claw.lua +++ b/claw/code-claw.lua @@ -3,7 +3,7 @@ return { ["neo"] = { desc = "KittenOS NEO Kernel & Base Libs", - v = 5, + v = 8, deps = { }, dirs = { @@ -67,7 +67,7 @@ return { }, ["neo-icecap"] = { desc = "KittenOS NEO / Icecap", - v = 7, + v = 8, deps = { "neo" }, @@ -125,7 +125,7 @@ return { }, ["neo-logo"] = { desc = "KittenOS NEO Logo (data)", - v = 6, + v = 8, deps = { }, dirs = { diff --git a/claw/repo-claw.lua b/claw/repo-claw.lua index 2af0a4f..c565b55 100644 --- a/claw/repo-claw.lua +++ b/claw/repo-claw.lua @@ -24,7 +24,7 @@ return { }, ["neo-docs"] = { desc = "KittenOS NEO system documentation", - v = 5, + v = 8, deps = { "zzz-license-pd" }, diff --git a/code/apps/sys-icecap.lua b/code/apps/sys-icecap.lua index f144a3b..43dc924 100644 --- a/code/apps/sys-icecap.lua +++ b/code/apps/sys-icecap.lua @@ -109,17 +109,20 @@ donkonitDFProvider(function (pkg, pid, sendSig) end end return { - showFileDialogAsync = function (forWrite) + showFileDialogAsync = function (forWrite, defName) if not rawequal(forWrite, nil) then require("sys-filewrap").ensureMode(forWrite) end + if not rawequal(defName, nil) then + defName = tostring(defName) + end -- Not hooked into the event API, so can't safely interfere -- Thus, this is async and uses a return event. local tag = {} neo.scheduleTimer(0) table.insert(todo, function () -- 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 end) return tag diff --git a/code/docs/logo.bmp b/code/docs/logo.bmp index 9fb2cdfbef0d29b1050d559fd21f64a41531b377..3802fb1d37f26276634f3ee08d9188fee9be80d5 100644 GIT binary patch delta 41 wcmZ1`vP@*c2_^>aiKmR1xq;MwBPMQ!$;OO^jNFq`8I744xEVIjX6)tw0P}bXZvX%Q delta 41 wcmZ1`vP@*c2_|laiKmR18GzJ(BPIs!$;OO^j0}@g8I75_xw$vbX6)tw0P;@?ZvX%Q diff --git a/code/libs/neoux.lua b/code/libs/neoux.lua index abb7cbd..0731de6 100644 --- a/code/libs/neoux.lua +++ b/code/libs/neoux.lua @@ -25,7 +25,7 @@ newNeoux = function (event, neo) end end) local neoux = {} - neoux.fileDialog = function (forWrite, callback) + neoux.fileDialog = function (forWrite, callback, dfn) local sync = false local rtt = nil if not callback then @@ -35,7 +35,7 @@ newNeoux = function (event, neo) rtt = rt 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 f = function (_, fd, tg, re) if fd == "filedialog" then diff --git a/code/libs/sys-filedialog.lua b/code/libs/sys-filedialog.lua index 4012224..7741ba4 100644 --- a/code/libs/sys-filedialog.lua +++ b/code/libs/sys-filedialog.lua @@ -2,7 +2,7 @@ -- No warranty is provided, implied or otherwise. -- 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 class = "manage" @@ -141,7 +141,7 @@ 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)) + prepareNode(require("sys-filevfs")(fs, mode, defName)) end if ev == "key" then key2(a, b, c) diff --git a/code/libs/sys-filevfs.lua b/code/libs/sys-filevfs.lua index c0c1f50..2ecb42f 100644 --- a/code/libs/sys-filevfs.lua +++ b/code/libs/sys-filevfs.lua @@ -16,12 +16,12 @@ end local getFsNode, getRoot local setupCopyNode -function setupCopyNode(parent, myRoot, op, complete, impliedName) +function setupCopyNode(parent, myRoot, op, complete) local function handleResult(aRes, res) if aRes then return complete(res, true) else - return nil, setupCopyNode(parent, res, op, complete, impliedName) + return nil, setupCopyNode(parent, res, op, complete) end end return { @@ -32,11 +32,6 @@ function setupCopyNode(parent, myRoot, op, complete, impliedName) complete(nil, false) return false, parent 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 table.insert(l, {v[1], function () return handleResult(v[2]()) @@ -54,7 +49,7 @@ local function setupCopyVirtualEnvironment(fs, parent, fwrap, impliedName) if not fwrap then return false, dialog("Could not open source", parent) end - local myRoot = getRoot(fs, true) + local myRoot = getRoot(fs, true, impliedName) -- Setup wrapping node return setupCopyNode(parent, myRoot, "Copy", function (fwrap2, intent) if not fwrap2 then @@ -72,14 +67,22 @@ local function setupCopyVirtualEnvironment(fs, parent, fwrap, impliedName) fwrap.close() fwrap2.close() return false, dialog("Completed copy.", parent) - end, impliedName) + 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 fscrw = not fsc.isReadOnly() local dir = path:sub(#path, #path) == "/" local confirmedDel = false 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 = { name = ((dir and "DIR: ") or "FILE: ") .. va .. path, list = function () @@ -94,18 +97,9 @@ function getFsNode(fs, parent, fsc, path, mode) if fsc.isDirectory(fp) then nm = "D: " .. v 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 - 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 dir then table.insert(n, {"Mk. Directory", function () @@ -156,37 +150,38 @@ function getFsNode(fs, parent, fsc, path, mode) end}) end end - if (fscrw or mode == false) and mode ~= nil then - local tx = "Open" - if mode == true then - tx = "Save" - elseif mode == "append" then - tx = "Append" - end - if fscrw or mode == false then - table.insert(n, {tx, function () - local rt, re = require("sys-filewrap").create(fsc, path, mode) - if not rt then - return false, dialog("Open Error: " .. tostring(re), parent) - end - return true, rt - 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}) + if (fscrw or mode == false) and (mode ~= nil) then + local tx = "Open" + if mode == true then + tx = "Save (Overwrite)" + elseif mode == "append" then + tx = "Append" + end + if fscrw or mode == false then + table.insert(n, {tx, selectUnknown}) + end end + elseif impliedName then + table.insert(n, {"Implied: " .. impliedName, function () + return selectUnknown(impliedName) + end}) end return n end, unknownAvailable = dir and (mode ~= nil) and ((mode == false) or fscrw), - selectUnknown = function (text) - 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 + selectUnknown = selectUnknown } return t end -function getRoot(fs, mode) +function getRoot(fs, mode, defName) local t t = { name = "DRVS:", @@ -210,7 +205,7 @@ function getRoot(fs, mode) id = "RW " .. amount .. "% " .. mb .. "M " .. id end 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 return l diff --git a/com2/bdivide.lua b/com2/bdivide.lua index 3710771..54b40a5 100644 --- a/com2/bdivide.lua +++ b/com2/bdivide.lua @@ -34,8 +34,12 @@ while blk ~= "" do break end local pm = p - 1 - bestData = string.char(128 + lm, math.floor(pm / 256), pm % 256) - bestRes = pfx + local thirdByte = pm % 256 + -- anti ']'-corruption helper + if thirdByte ~= 93 then + bestData = string.char(128 + lm, math.floor(pm / 256), thirdByte) + bestRes = pfx + end end -- ok, encode! io.write(bestData) diff --git a/repository/docs/ul-fwrap b/repository/docs/ul-fwrap index e411360..4c066bc 100644 --- a/repository/docs/ul-fwrap +++ b/repository/docs/ul-fwrap @@ -15,10 +15,12 @@ The mode you give to it can be one of true: Write "wb" "append": Append "ab" May have some readability - propertiues - just in + properties - just in case, I've added 'read', but don't get your hopes up... + "access": Like read, but can be + re-opened for write. It returns two things - a table, that being the file object, and the @@ -37,7 +39,9 @@ The possible functions are: [aw] write(data): Writes to the file. [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 work. They're just there as more or diff --git a/repository/docs/ul-neoux b/repository/docs/ul-neoux index 82cf015..35c99af 100644 --- a/repository/docs/ul-neoux +++ b/repository/docs/ul-neoux @@ -33,16 +33,19 @@ The most reliable reference on the Main functions: - fileDialog(mode[, callback]): + neoux.fileDialog(mode, [callback], + [dfn]): Creates a file dialog, returning a file wrapper (see ul-fwrap) on 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 - the callback is called when the - dialog has shown. + the callback is called with the + result when the dialog is closed. mode is the mode used for the file, so see ul-fwrap for values. + dfn is, if not nil, the default + 'implied' filename (as with Copy). neoux.create(w, h, title, callback): Creates a window, diff --git a/repository/docs/us-perms b/repository/docs/us-perms index ad01930..7a8f7dd 100644 --- a/repository/docs/us-perms +++ b/repository/docs/us-perms @@ -57,11 +57,15 @@ Paths for the IO parts of this API the standard KittenOS NEO path safety rules in the kernel. - showFileDialogAsync(mode): Shows a - filedialog with a given filemode, - or nil for "none". Returns a new, - empty table as a "tag", and emits a - "filedialog" event on completion. + showFileDialogAsync(mode, dfn): + Shows a filedialog with a given + filemode, or nil for "none". + Returns a new, empty table as a + "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" for the program svc-abc, used for