1
0
mirror of https://github.com/kepler155c/opus synced 2025-02-06 20:20:03 +00:00
opus/sys/autorun/complete.lua

36 lines
1001 B
Lua
Raw Normal View History

local fs = _G.fs
2019-02-11 20:25:12 -05:00
local function completeMultipleChoice(sText, tOptions, bAddSpaces)
2019-06-18 15:19:24 -04:00
local tResults = { }
for n = 1,#tOptions do
local sOption = tOptions[n]
if #sOption + (bAddSpaces and 1 or 0) > #sText and string.sub(sOption, 1, #sText) == sText then
local sResult = string.sub(sOption, #sText + 1)
if bAddSpaces then
table.insert(tResults, sResult .. " ")
else
table.insert(tResults, sResult)
end
end
end
return tResults
2019-02-11 20:25:12 -05:00
end
_ENV.shell.setCompletionFunction("sys/apps/package.lua",
2019-06-18 15:19:24 -04:00
function(_, index, text)
if index == 1 then
2019-07-03 10:44:30 -04:00
return completeMultipleChoice(text, { "install ", "update ", "uninstall ", "updateall ", "refresh" })
2019-06-18 15:19:24 -04:00
end
end)
_ENV.shell.setCompletionFunction("sys/apps/inspect.lua",
function(_, index, text)
if index == 1 then
local components = { }
for _, f in pairs(fs.list('sys/modules/opus/ui/components')) do
table.insert(components, (f:gsub("%.lua$", "")))
end
return completeMultipleChoice(text, components)
end
end)