From 1de5f9ac6f038bfed2230cc1272b253794b2f41a Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 10 Jul 2016 17:04:29 -0400 Subject: Initial commit --- gamemode/shared/concommands.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 gamemode/shared/concommands.lua (limited to 'gamemode/shared/concommands.lua') diff --git a/gamemode/shared/concommands.lua b/gamemode/shared/concommands.lua new file mode 100644 index 0000000..b4e844a --- /dev/null +++ b/gamemode/shared/concommands.lua @@ -0,0 +1,28 @@ +--[[ + Various console command helper functions +]] + +local fuzzel = include("fuzzel.lua") + +local concmd = {} + +function concmd.AutocompleteFunction(...) + local opt = {...} + opt = type(opt[1]) == "table" and opt[1] or opt + return function(cmd,strargs) + --Remove spaces and quotes, since we don't want to match them + strargs = string.gsub(strargs,"[\" ]","") + --Find the options that most closely resemble our command so far + local sorted = fuzzel.fad(strargs,opt) + --Add quotes if needed, and preppend the command to each option + for k,v in pairs(sorted) do + if string.find(v," ") ~= nil then + sorted[k] = "\"" .. v .. "\"" + end + sorted[k] = cmd .. " " .. sorted[k] + end + return sorted + end +end + +return concmd -- cgit v1.2.3-70-g09d2