Improve help and fix blank output after reinit
* Add clear to help * Add off/shutdown to help * Add reboot/restart to help * Sort help alphabetically * Ensure that start.lua is automatically run after the filesystem is reinitialized in order to prevent the output buffer from being emptymaster
parent
e930f0715f
commit
fdeb68a5d5
|
@ -162,7 +162,7 @@ digicompute.c.forms = {
|
|||
},
|
||||
main = {
|
||||
get = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
local last_start = meta:get_int("last_run_start")
|
||||
if last_start == 0 or last_start < meta:get_int("last_boot") then
|
||||
|
@ -254,6 +254,10 @@ digicompute.c.forms = {
|
|||
|
||||
-- Reset Filesystem
|
||||
digicompute.c:reinit(pos)
|
||||
|
||||
-- Rerun start.lua
|
||||
meta:set_int("last_run_start", os.time())
|
||||
digicompute.c:run_file(pos, "os/start.lua")
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
|
|
@ -4,6 +4,30 @@ local params = ...
|
|||
local bin = get_userdata("bin")
|
||||
local param = params[1]
|
||||
|
||||
--[local function] Sort the help list alphabetically
|
||||
local function sort(list)
|
||||
-- Order map
|
||||
local map = {["0"] = 1, ["1"] = 2, ["2"] = 3, ["3"] = 4, ["4"] = 5, ["5"] = 6, ["6"] = 7,
|
||||
["7"] = 8, ["8"] = 9, ["9"] = 10, a = 11, b = 12, c = 13, d = 14, e = 15, f = 16, g = 17,
|
||||
h = 18, i = 19, j = 20, k = 21, l = 22, m = 23, n = 24, o = 25, p = 26, q = 27, r = 28,
|
||||
s = 29, t = 30, u = 31, v = 32, w = 33, x = 34, y = 35, z = 36}
|
||||
|
||||
local keys = {}
|
||||
for k in pairs(list) do keys[#keys + 1] = k end
|
||||
|
||||
-- Detect sort order and sort using custom comparison functions
|
||||
table.sort(keys, function(a, b) return map[a:sub(1, 1):lower()] < map[b:sub(1, 1):lower()] end)
|
||||
|
||||
-- Return iterator function
|
||||
local i = 0
|
||||
return function()
|
||||
i = i + 1
|
||||
if keys[i] then
|
||||
return keys[i], list[keys[i]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- [local function] Print help
|
||||
local function print_h(name, info)
|
||||
local cparams = ""
|
||||
|
@ -15,7 +39,7 @@ local function print_h(name, info)
|
|||
end
|
||||
|
||||
if param == "all" then
|
||||
for name, info in pairs(bin) do
|
||||
for name, info in sort(bin) do
|
||||
print_h(name, info)
|
||||
end
|
||||
elseif not param or param == "" then
|
||||
|
|
|
@ -21,6 +21,11 @@ for _,f in ipairs(bin_contents.files) do
|
|||
}
|
||||
end
|
||||
|
||||
-- Add additional commands to bin
|
||||
bin[get_os("clear")] = { description = "Clear the shell output" } -- Clear shell output
|
||||
bin[get_os("off")] = { description = "Turn off computer" } -- Turn off computer
|
||||
bin[get_os("reboot")] = { description = "Reboot computer" } -- Reboot computer
|
||||
|
||||
-- Save bin table
|
||||
set_userdata("bin", bin)
|
||||
|
||||
|
|
Loading…
Reference in New Issue