ComputerCraft Archive

complete

computer utility kepler155c github

Description

ComputerCraft OS

Installation

Copy one of these commands into your ComputerCraft terminal:

wget:wget https://raw.githubusercontent.com/kepler155c/opus/develop-1.8/sys/autorun/complete.lua complete
Archive:wget https://cc.shobie.xyz/cc/get/gh-kepler155c-opus-sys-autorun-complete complete
Quick Install: wget https://cc.shobie.xyz/cc/get/gh-kepler155c-opus-sys-autorun-complete complete

Usage

Run: complete

Tags

none

Source

View Original Source

Code Preview

local fs = _G.fs

local function completeMultipleChoice(sText, tOptions, bAddSpaces)
	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
end

_ENV.shell.setCompletionFunction("sys/apps/package.lua",
	function(_, index, text)
		if index == 1 then
			return completeMultipleChoice(text, { "install ", "update ", "uninstall ", "updateall ", "refresh" })
		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{{code}}quot;, "")))
			end
			return completeMultipleChoice(text, components)
		end
	end)