Version 0.9.0-rc1

- enable/disable from slash command
- matching conditions (never, always, start, end, start or end)
- support capturing groups
- import examples
- testing capabilities
- compatibility with WoW Retail
- adapted help texts
- spelling errors
This commit is contained in:
2020-07-16 12:54:06 +02:00
parent cc4df96bac
commit bafb116bb9
39 changed files with 3043 additions and 1049 deletions

View File

@@ -1,18 +1,33 @@
-- import addon read namespace from global env
local _G = _G
local Grichelde = _G.Grichelde
local Grichelde = _G.Grichelde or {}
local type, print, pairs, tSize, select, unpack, find, color, cGray, cDarkgray, cPrefix, format, rep, toString
= Grichelde.functions.type, Grichelde.functions.print, Grichelde.functions.pairs, Grichelde.functions.tSize, Grichelde.functions.select, Grichelde.functions.unpack, Grichelde.functions.find, Grichelde.functions.color, Grichelde.functions.cGray, Grichelde.functions.cDarkgray, Grichelde.functions.cPrefix, Grichelde.functions.format, Grichelde.functions.rep, Grichelde.functions.toString
local type, print, pairs, tSize, select, unpack, find, sub, gsub, cGray, cDarkgray, cRed, cPrefix, format, rep, toString, toNumber
= Grichelde.F.type, Grichelde.F.print, Grichelde.F.pairs, Grichelde.F.tSize, Grichelde.F.select, Grichelde.F.unpack, Grichelde.F.find, Grichelde.F.sub, Grichelde.F.gsub, Grichelde.F.cGray, Grichelde.F.cDarkgray, Grichelde.F.cRed, Grichelde.F.cPrefix, Grichelde.F.format, Grichelde.F.rep, Grichelde.F.toString, Grichelde.F.toNumber
function Grichelde:ParseVersion(version)
local _, _, major, minor, patch, ext = find(version, "(%d+)%.(%d+)%.(%d+)(.*)")
local preBuild, build = ext, ""
if (sub(ext, 1, 1) == "-") then
local b = find(ext, "+", 2)
if (b ~= nil) then
preBuild = sub(ext, 1, b)
build = sub(ext, b + 1)
else
preBuild = sub(ext, 1, b)
end
end
return toNumber(major) or 0, toNumber(minor) or 0, toNumber(patch) or 0, preBuild, build
end
-- show strings differently to distinguish them from numbers
local function plainValue(val)
if val == nil then
function Grichelde:plainValue(val)
if (val == nil) then
return "<nil>"
elseif type(val) == "string" then
elseif (type(val) == "string") then
return '"' .. val .. '"'
elseif type(val) == "table" then
if tSize(val) > 0 then
elseif (type(val) == "table") then
if (tSize(val) > 0) then
return toString(val)
else
return "{}"
@@ -23,33 +38,36 @@ local function plainValue(val)
end
--- Prints any value to default channel, do NOT return a string.
local function tPrint(val, indent, known, printFunc)
function Grichelde:tPrint(val, indent, known, printFunc)
local printF = printFunc or print
indent = indent or 0
known = known or {}
if val == nil then
if (val == nil) then
printF(rep(" ", indent) .. "<nil>")
elseif type(val) == "string" then
elseif (type(val) == "string") then
printF(rep(" ", indent) .. "\"" .. val .. "\"")
elseif type(val) == "table" then
if tSize(val) > 0 then
elseif (type(val) == "table") then
if (tSize(val) > 0) then
for key, value in pairs(val) do
if value == nil then
printF(rep(" ", indent) .. plainValue(key) .. " = <nil>")
elseif type(value) == "table" then
printF(rep(" ", indent) .. plainValue(key) .. " = {")
if tSize(value) > 0 then
if (value == nil) then
printF(rep(" ", indent) .. self:plainValue(key) .. " = <nil>")
elseif (type(value) == "table") then
printF(rep(" ", indent) .. self:plainValue(key) .. " = {")
if (tSize(value) > 0) then
if not known[value] then
tPrint(value, indent + 4, known, printF)
self:tPrint(value, indent + 4, known, printF)
known[value] = true
else
printF("<known table> " .. plainValue(value))
printF("<known table> " .. self:plainValue(value))
end
end
printF(rep(" ", indent) .. "}")
else
printF(rep(" ", indent) .. plainValue(key) .. " = " .. plainValue(value))
local k = self:plainValue(key)
local v = self:plainValue(value)
--print( "k: " .. k .. ", v: " ..v)
printF(rep(" ", indent) .. k .. " = " .. v)
end
end
else
@@ -62,7 +80,7 @@ end
--- Splits at first word of a text line
function Grichelde:SplitOnFirstMatch(text, delimPattern, start)
if text == nil then return nil end
if (text == nil) then return nil end
local pattern = "^(.-)" .. (delimPattern or " " ) .."(.*)"
local pos = start or 1
self:TracePrint("SplitOnFirstMatch : text: %s, pattern: %s, start: %d", text, pattern, start)
@@ -88,82 +106,85 @@ function Grichelde:TestMatch(text, pattern)
end
function Grichelde:Format(message, ...)
if ( not message ) then
if (message == nil) then
return "<nil>"
elseif type(message) == "string" then
if ( not find(message, "%%")) then
elseif (type(message) == "string") then
if (find(message, "%%") == nil) then
--print("message: ", message)
--print("...: ", ...)
return message, ...
else
local l = select("#", ...)
if l > 0 then
if (l > 0) then
-- sanitize nil values in vararg
local packed = { ... }
for i = 1, l do
packed[i] = toString(packed[i]) or "nil"
--print("packed[i] = ", packed[i])
--packed[i] = gsub(packed[i], "%%(%d)", "%%%%%1")
end
-- print("packed = ", packed)
-- self:tPrint(packed)
-- cannot assign unpacked to a vararg variable and print it for debug
-- Manually set count as unpack() stops on nil (bug with #table)
return format(message, unpack(packed, 1, l))
else
return message
end
end
end
end
--- deprecated
function Grichelde:Print(...)
print(self:Format(...))
end
function Grichelde:PrefixedPrint(...)
print(cPrefix(self.L.AddonName) .. ":", self:Format(...))
end
function Grichelde:ErrorPrint(...)
print(cPrefix(self.L.AddonName) .. ": " .. color(self.COLOR_CODES.RED, self:Format(...)))
print(cPrefix(self.L.AddonName) .. ": " .. cRed(self:Format(...)))
end
function Grichelde:DebugPrint(obj, ...)
self:LogPrint(Grichelde.LOG_LEVEL.DEBUG, function(...)
print(cGray(self.L.AddonName) .. ":", self:Format(...))
end, obj, ...)
if (self.logLevel >= Grichelde.LOG_LEVEL.DEBUG) then
self:LogPrint(function(...)
print(cGray(self.L.AddonName) .. ":", self:Format(...))
end, obj, ...)
end
end
function Grichelde:TracePrint(obj, ...)
self:LogPrint(Grichelde.LOG_LEVEL.TRACE, function(...)
print(cDarkgray(self.L.AddonName) .. ":", self:Format(...))
end, obj, ...)
if (self.logLevel >= Grichelde.LOG_LEVEL.TRACE) then
self:LogPrint(function(...)
print(cDarkgray(self.L.AddonName) .. ":", self:Format(...))
end, obj, ...)
end
end
function Grichelde:LogPrint(logLevel, printFunc, obj, ...)
if (self.logLevel >= logLevel) then
local printF = printFunc or print
if obj == nil then
printF("<nil>")
else
if type(obj) == "string" then
local l = select("#", ...)
if ( l == 0 or not find(obj, "%%")) then
printF(obj, ...)
else
-- sanitize nil values in vararg
local packed = { ... }
for i = 1, l do
packed[i] = toString(packed[i]) or "nil"
end
-- print("packed = ", packed)
-- self:tPrint(packed)
-- cannot assign unpacked to a vararg variable and print it for debug
local fmtMsg = format(obj, unpack(packed, 1, l)) -- manually set count as unpack() stops on nil (bug with #table)
printF(fmtMsg)
end
elseif type(obj) == "table" then
tPrint(obj, 0, {}, printF)
function Grichelde:LogPrint(printFunc, obj, ...)
local printF = printFunc or print
if obj == nil then
printF("<nil>")
else
if type(obj) == "string" then
local l = select("#", ...)
if (l == 0) or (find(obj, "%%") == nil) then
printF(obj, ...)
else
printF(plainValue(obj))
-- sanitize nil values in vararg
local packed = { ... }
for i = 1, l do
packed[i] = toString(packed[i]) or "nil"
end
-- print("packed = ", packed)
-- self:tPrint(packed)
-- cannot assign unpacked to a vararg variable and print it for debug
local fmtMsg = format(obj, unpack(packed, 1, l)) -- manually set count as unpack() stops on nil (bug with #table)
printF(fmtMsg)
end
elseif (type(obj) == "table") then
self:tPrint(obj, 0, {}, printF)
else
printF(self:plainValue(obj))
end
end
end
@@ -196,7 +217,7 @@ end
function Grichelde:ToogleMappings()
local AceGUI = LibStub("AceGUI-3.0")
if self.debugFrame then
if (self.debugFrame ~= nil) then
AceGUI:Release(self.debugFrame)
self.debugFrame = nil
else
@@ -231,7 +252,7 @@ function Grichelde:ToogleMappings()
local configBox = AceGUI:Create("MultiLineEditBox");
configBox:SetLabel("")
local text = ""
tPrint(replacements, 0, {}, function(s) text = text .. s .. "|n" end)
self:tPrint(replacements, 0, {}, function(s) text = text .. s .. "|n" end)
configBox:SetText(text)
configBox:SetFullWidth(true)
--configBox:SetFullHeight(true)