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,45 +1,46 @@
-- read namespace from global env
local _G = _G
local Grichelde = _G.Grichelde
local Grichelde = _G.Grichelde or {}
-- constants and upvalues
Grichelde.LOG_LEVEL = {}
Grichelde.LOG_LEVEL.DEBUG = 1
Grichelde.LOG_LEVEL.TRACE = 2
Grichelde.LOG_LEVEL = { DEBUG = 1, TRACE = 2 }
Grichelde.MAPPING_OFFSET = 10
Grichelde.MINIMAP_ENABLED = 1.0
Grichelde.MINIMAP_DARKENDED = 0.5
Grichelde.ICONS = {}
Grichelde.ICONS.MOVE_UP = "Interface\\MainMenuBar\\UI-MainMenu-ScrollUpButton-Up"
Grichelde.ICONS.MOVE_UP_DISABLED = "Interface\\MainMenuBar\\UI-MainMenu-ScrollUpButton-Disabled"
Grichelde.ICONS.MOVE_DOWN = "Interface\\MainMenuBar\\UI-MainMenu-ScrollDownButton-Up"
Grichelde.ICONS.MOVE_DOWN_DISABLED = "Interface\\MainMenuBar\\UI-MainMenu-ScrollDownButton-Disabled"
Grichelde.ICONS.DELETE = "Interface\\Buttons\\UI-Panel-MinimizeButton-Up"
Grichelde.ICONS.DELETE_DISABLED = "Interface\\Buttons\\UI-Panel-MinimizeButton-Disabled"
Grichelde.ICONS = {
MOVE_UP = "Interface\\MainMenuBar\\UI-MainMenu-ScrollUpButton-Up",
MOVE_UP_DISABLED = "Interface\\MainMenuBar\\UI-MainMenu-ScrollUpButton-Disabled",
MOVE_DOWN = "Interface\\MainMenuBar\\UI-MainMenu-ScrollDownButton-Up",
MOVE_DOWN_DISABLED = "Interface\\MainMenuBar\\UI-MainMenu-ScrollDownButton-Disabled",
DELETE = "Interface\\Buttons\\UI-Panel-MinimizeButton-Up",
DELETE_DISABLED = "Interface\\Buttons\\UI-Panel-MinimizeButton-Disabled",
}
-- colors:
Grichelde.COLORS = {}
Grichelde.COLORS.NORMAL = _G.NORMAL_FONT_COLOR
Grichelde.COLORS.HIGHLIGHT = _G.HIGHLIGHT_FONT_COLOR
Grichelde.COLORS.RED = _G.RED_FONT_COLOR
Grichelde.COLORS.GREEN = _G.GREEN_FONT_COLOR
Grichelde.COLORS = {
NORMAL = _G.NORMAL_FONT_COLOR,
HIGHLIGHT = _G.HIGHLIGHT_FONT_COLOR,
RED = _G.RED_FONT_COLOR,
GREEN = _G.GREEN_FONT_COLOR,
}
Grichelde.COLOR_CODES = {}
Grichelde.COLOR_CODES.PREFIX = "|c00FFAA00"
-- https://github.com/stoneharry/Misc-WoW-Stuff/blob/master/EoC%20Interface/FrameXML/Constants.lua
Grichelde.COLOR_CODES.NORMAL = _G.NORMAL_FONT_COLOR_CODE or "|cffffd200"
Grichelde.COLOR_CODES.HIGHLIGHT = _G.HIGHLIGHT_FONT_COLOR_CODE or "|cffffffff"
Grichelde.COLOR_CODES.RED = _G.RED_FONT_COLOR_CODE or "|cffff2020"
Grichelde.COLOR_CODES.GREEN = _G.GREEN_FONT_COLOR_CODE or "|cff20ff20"
Grichelde.COLOR_CODES.LIGHTGRAY = "|cffC0C0C0"
Grichelde.COLOR_CODES.GRAY = _G.GRAY_FONT_COLOR_CODE or "|cff808080"
Grichelde.COLOR_CODES.DARKGRAY = "|cff404040"
Grichelde.COLOR_CODES.YELLOW = _G.YELLOW_FONT_COLOR_CODE or "|cffffff00"
Grichelde.COLOR_CODES.LIGHTYELLOW = _G.LIGHTYELLOW_FONT_COLOR_CODE or "|cffffff9a"
Grichelde.COLOR_CODES.ORANGE = _G.ORANGE_FONT_COLOR_CODE or "|cffff7f3f"
Grichelde.COLOR_CODES.CLOSE = _G.FONT_COLOR_CODE_CLOSE or "|r"
Grichelde.COLOR_CODES = {
PREFIX = "|c00FFAA00",
-- https://github.com/stoneharry/Misc-WoW-Stuff/blob/master/EoC%20Interface/FrameXML/Constants.lua
NORMAL = _G.NORMAL_FONT_COLOR_CODE or "|cffffd200",
HIGHLIGHT = _G.HIGHLIGHT_FONT_COLOR_CODE or "|cffffffff",
RED = _G.RED_FONT_COLOR_CODE or "|cffff2020",
GREEN = _G.GREEN_FONT_COLOR_CODE or "|cff20ff20",
LIGHTGRAY = "|cffC0C0C0",
GRAY = _G.GRAY_FONT_COLOR_CODE or "|cff808080",
DARKGRAY = "|cff404040",
YELLOW = _G.YELLOW_FONT_COLOR_CODE or "|cffffff00",
LIGHTYELLOW = _G.LIGHTYELLOW_FONT_COLOR_CODE or "|cffffff9a",
ORANGE = _G.ORANGE_FONT_COLOR_CODE or "|cffff7f3f",
CLOSE = _G.FONT_COLOR_CODE_CLOSE or "|r",
}
Grichelde.SLASH_COMMANDS = { "gri", "grichelde" }
@@ -113,39 +114,52 @@ Grichelde.BLIZZ_TYPE_TO_OPTIONS = {
}
-- do not replace these patterns
Grichelde.IGNORE_PATTERNS_CASE_SENSITIVE = {
"|[Cc]%x%x%x%x%x%x%x%x.-|r", -- colored items (or links)
"|H.-|h", -- item links (http://www.wowwiki.com/ItemLink)
"|T.-|t", -- textures
"|K.-|k", -- Battle.net
"|n", -- newline
"%(%(.-%)%)", -- (( ... ))
"%(%s*ooc[%:%s].-%)", -- ( ooc )
Grichelde.IGNORE_PATTERNS = {
LINKS = {
"|[Cc]%x%x%x%x%x%x%x%x.-|r", -- colored items (or links)
"|H.-|h", -- item links (http://www.wowwiki.com/ItemLink)
"|T.-|t", -- textures
"|K.-|k", -- Battle.net
"|n", -- newline
},
EMOTES = {
"%*.-%*", -- emotes *
"%*%*.-%*%*", -- emotes **
"%<.-%>", -- emotes < >
},
SUBSTITUTES = {
"%%n", -- player's name
"%%z", -- player's currnt zone
"%%sz", -- player's current sub-zone
"%%loc", -- player's map coordinates
"%%t", -- name of target
"%%f", -- name of focus target
"%%m", -- name of mouseover unit
"%%p", -- name of player pet
"%%tt", -- name of player's target's target
},
RAID_TARGETS = {
"{rt[1-8]}", -- rumbered raid target icons, localized raid targets are handled differently
},
LOCALIZED_RAID_TARGETS = {
"Star",
"Circle",
"Diamond",
"Triangle",
"Moon",
"Square",
"Cross",
"Skull",
},
OOC_BRACKETS = {
"%(%(.-%)%)", -- (( ... ))
"%(%s*ooc[%:%s].-%)", -- ( ooc )
},
OOC_NO_BRACKETS = {
"ooc[%:%s]",
},
}
-- for separate emote detection
Grichelde.EMOTE_PATTERNS = {
"%*.-%*", -- emotes *
"%*%*.-%*%*", -- emotes **
"%<.-%>" -- emotes < >
}
Grichelde.IGNORE_PATTERNS_CASE_INSENSITIVE = {
"{rt[1-8]}", -- rumbered raid target icons, localized raid targets are handled differently
"%%n", -- player's name
"%%z", -- player's currnt zone
"%%sz", -- player's current sub-zone
"%%loc", -- player's map coordinates
"%%t", -- name of target
"%%f", -- name of focus target
"%%m", -- name of mouseover unit
"%%p", -- name of player pet
"%%tt" -- name of player's target's target
}
Grichelde.LOCALIZED_RAID_TARGETS = { "Star", "Circle", "Diamond", "Triangle", "Moon", "Square", "Cross", "Skull" }
local function nilOrEmpty(s)
return s == nil or s:trim() == ""
end
@@ -154,22 +168,22 @@ local function spairs(t, orderFunc)
-- collect the keys
local sortedKeys = {}
-- for every non-nil value
for key, _ in Grichelde.functions.pairs(t) do
Grichelde.functions.tInsert(sortedKeys, key)
for key, _ in Grichelde.F.pairs(t) do
Grichelde.F.tInsert(sortedKeys, key)
end
if orderFunc then
Grichelde.functions.tSort(sortedKeys, function(a, b) return orderFunc(sortedKeys, a, b) end)
if (orderFunc ~= nil) then
Grichelde.F.tSort(sortedKeys, function(a, b) return orderFunc(sortedKeys, a, b) end)
else
-- lexicographical order
Grichelde.functions.tSort(sortedKeys)
Grichelde.F.tSort(sortedKeys)
end
-- return the iterator function
local it = 0
return function()
it = it + 1
if sortedKeys[it] then
if (sortedKeys[it] ~= nil) then
return sortedKeys[it], t[sortedKeys[it]]
else
return nil
@@ -179,23 +193,23 @@ end
local function tFilter(t, condition, extract)
local filtered = {}
for key, value in Grichelde.functions.pairs(t) do
for key, value in Grichelde.F.pairs(t) do
local cond = false
if condition then
local t = Grichelde.functions.type(condition)
if t == "function" then
if (condition) then
local t = Grichelde.F.type(condition)
if (t == "function") then
cond = condition(t, key, value)
elseif t == "string" or t == "number" then
elseif (t == "string") or (t == "number") then
cond = (value == condition)
end
end
if cond then
if (cond) then
local val = value
if extract and Grichelde.functions.type(extract) == "function" then
if (extract and (Grichelde.F.type(extract) == "function")) then
val = extract(t, key, value)
end
Grichelde.functions.tInsert(filtered, val)
Grichelde.F.tInsert(filtered, val)
end
end
return filtered
@@ -203,9 +217,9 @@ end
local function tSize(t)
local size = 0
if (t) then
if (t ~= nil) then
-- for every non-nil value
for _, _ in Grichelde.functions.pairs(t) do
for _, _ in Grichelde.F.pairs(t) do
size = size + 1
end
end
@@ -214,45 +228,117 @@ end
local function tIsEmpty(t)
if (not t) then return true end
return Grichelde.functions.tNext(t) == nil
return Grichelde.F.tNext(t) == nil
end
local function tClone(orig)
local orig_type = Grichelde.functions.type(orig)
local orig_type = Grichelde.F.type(orig)
local copy
if orig_type == 'table' then
if (orig_type == 'table') then
copy = {}
-- for every non-nil value
for orig_key, orig_value in Grichelde.functions.tNext, orig, nil do
for orig_key, orig_value in Grichelde.F.tNext, orig, nil do
copy[tClone(orig_key)] = tClone(orig_value)
end
Grichelde.functions.setmetatable(copy, tClone(Grichelde.functions.getmetatable(orig)))
Grichelde.F.setmetatable(copy, tClone(Grichelde.F.getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end
return copy
end
local function isChar(word)
return Grichelde.functions.find(word, "[%z\65-\90\97-\122\195-\197][\128-\191]?")
local function getNextCharUtf8(word)
if ((word == nil) or (Grichelde.F.type(word) ~= "string") or (Grichelde.F.length(word) < 1)) then
return nil, nil
end
local wordLength = Grichelde.F.length(word)
local c1 = Grichelde.F.toByte(word, 1)
if (c1 > 0) and (c1 <= 127) then
-- UTF8-1
return Grichelde.F.bytes2Char(c1), Grichelde.F.sub(word, 2)
elseif (c1 >= 194) and (c1 <= 223) then
-- UTF8-2
Grichelde.F.assert(wordLength >= 2, "broken UTF-8 character")
local c2 = Grichelde.F.toByte(word, 2)
return Grichelde.F.bytes2Char(c1, c2), Grichelde.F.sub(word, 3)
elseif (c1 >= 224) and (c1 <= 239) then
-- UTF8-3
Grichelde.F.assert(wordLength >= 3, "broken UTF-8 character")
local c2 = Grichelde.F.toByte(word, 2)
local c3 = Grichelde.F.toByte(word, 3)
return Grichelde.F.bytes2Char(c1, c2, c3), Grichelde.F.sub(word, 4)
elseif (c1 >= 240) and (c1 <= 244) then
-- UTF8-4
Grichelde.F.assert(wordLength >= 4, "broken UTF-8 character")
local c2 = Grichelde.F.toByte(word, 2)
local c3 = Grichelde.F.toByte(word, 3)
local c4 = Grichelde.F.toByte(word, 4)
return Grichelde.F.bytes2Char(c1, c2, c3, c4), Grichelde.F.sub(word, 5)
else
return nil, nil
end
end
local function isLetter(word)
local char = Grichelde.F.getNextCharUtf8(word)
return (char ~= nil) and (Grichelde.F.toUpper(char) ~= Grichelde.F.toLower(char))
end
local function isNumber(digit)
return Grichelde.functions.find(digit, "%d+")
if ((digit == nil) or (Grichelde.F.type(digit) ~= "string") or (Grichelde.F.length(digit) < 1)) then
return false
else
return Grichelde.F.find(digit, "%d+") ~= nil
end
end
local function isUpper(word)
return Grichelde.functions.isChar(word) and word == Grichelde.functions.toUpper(word)
if ((word == nil) or (Grichelde.F.type(word) ~= "string") or (Grichelde.F.length(word) < 1)) then
return false
elseif (Grichelde.F.toUpper(word) == Grichelde.F.toLower(word)) then
return false
else
return word == Grichelde.F.toUpper(word)
end
end
local function isLower(word)
return Grichelde.functions.isChar(word) and word == Grichelde.functions.toLower(word)
if ((word == nil) or (Grichelde.F.type(word) ~= "string") or (Grichelde.F.length(word) < 1)) then
return false
elseif (Grichelde.F.toUpper(word) == Grichelde.F.toLower(word)) then
return false
else
return word == Grichelde.F.toLower(word)
end
end
local function isCapital(word)
return Grichelde.functions.legnth(word) > 1
and Grichelde.functions.isUpper(Grichelde.functions.sub(word,1,1))
and Grichelde.functions.isLower(Grichelde.functions.sub(word,2))
if ((word == nil) or (Grichelde.F.type(word) ~= "string") or (Grichelde.F.length(word) < 1)) then
return false
else
local first, rest = Grichelde.F.getNextCharUtf8(word)
local isCapital = Grichelde.F.isUpper(first)
if (rest ~= nil) then
return isCapital and Grichelde.F.isLower(rest)
else
return isCapital
end
end
end
local function capitalize(word)
if ((word == nil) or (Grichelde.F.type(word) ~= "string") or (Grichelde.F.length(word) < 1)) then
return ""
else
local first, rest = Grichelde.F.getNextCharUtf8(word)
local capital = Grichelde.F.toUpper(first)
if (rest ~= nil) then
return capital .. Grichelde.F.toLower(rest)
else
return capital
end
end
end
local function color(color, text)
@@ -260,74 +346,90 @@ local function color(color, text)
end
local function cPrefix(text)
return Grichelde.functions.color(Grichelde.COLOR_CODES.PREFIX, text)
return Grichelde.F.color(Grichelde.COLOR_CODES.PREFIX, text)
end
local function cYellow(text)
return Grichelde.functions.color(Grichelde.COLOR_CODES.NORMAL, text)
return Grichelde.F.color(Grichelde.COLOR_CODES.NORMAL, text)
end
local function cGray(text)
return Grichelde.functions.color(Grichelde.COLOR_CODES.GRAY, text)
return Grichelde.F.color(Grichelde.COLOR_CODES.GRAY, text)
end
local function cDarkgray(text)
return Grichelde.functions.color(Grichelde.COLOR_CODES.DARKGRAY, text)
return Grichelde.F.color(Grichelde.COLOR_CODES.DARKGRAY, text)
end
local function cGreen(text)
return Grichelde.F.color(Grichelde.COLOR_CODES.GREEN, text)
end
local function cOrange(text)
return Grichelde.functions.color(Grichelde.COLOR_CODES.ORANGE, text)
return Grichelde.F.color(Grichelde.COLOR_CODES.ORANGE, text)
end
local function cRed(text)
return Grichelde.F.color(Grichelde.COLOR_CODES.RED, text)
end
-- faster function lookups by mapping to local refs
Grichelde.functions = {}
Grichelde.functions.IsAddOnLoaded = _G.IsAddOnLoaded
Grichelde.functions.assert = _G.assert
Grichelde.functions.type = _G.type
Grichelde.functions.print = _G.print
Grichelde.functions.nilOrEmpty = nilOrEmpty
Grichelde.functions.pairs = _G.pairs
Grichelde.functions.ipairs = _G.ipairs
Grichelde.functions.spairs = spairs
Grichelde.functions.tContains = _G.tContains
Grichelde.functions.tFilter = tFilter
Grichelde.functions.tInsert = _G.table.insert
Grichelde.functions.tConcat = _G.table.concat
Grichelde.functions.tSize = tSize
Grichelde.functions.tIsEmpty = tIsEmpty
Grichelde.functions.tSort = _G.table.sort
Grichelde.functions.tClone = tClone
Grichelde.functions.tNext = _G.next
Grichelde.functions.tWipe = _G.wipe
Grichelde.functions.setmetatable = _G.setmetatable
Grichelde.functions.getmetatable = _G.getmetatable
Grichelde.functions.select = _G.select
Grichelde.functions.unpack = _G.unpack
Grichelde.functions.find = _G.string.find
Grichelde.functions.sub = _G.string.sub
Grichelde.functions.gsub = _G.string.gsub
Grichelde.functions.match = _G.strmatch
Grichelde.functions.join = _G.strjoin
Grichelde.functions.split = _G.strsplit
Grichelde.functions.toUpper = _G.strupper
Grichelde.functions.toLower = _G.strlower
Grichelde.functions.isChar = isChar
Grichelde.functions.isNumber = isNumber
Grichelde.functions.isUpper = isUpper
Grichelde.functions.isLower = isLower
Grichelde.functions.isCapital = isCapital
Grichelde.functions.color = color
Grichelde.functions.cPrefix = cPrefix
Grichelde.functions.cYellow = cYellow
Grichelde.functions.cGray = cGray
Grichelde.functions.cDarkgray = cDarkgray
Grichelde.functions.cOrange = cOrange
Grichelde.functions.format = _G.string.format
Grichelde.functions.rep = _G.string.rep
Grichelde.functions.trim = _G.strtrim
Grichelde.functions.length = _G.string.len
Grichelde.functions.lenUtf8 = _G.strlenutf8
Grichelde.functions.toString = _G.tostring
Grichelde.functions.toNumber = _G.tonumber
Grichelde.functions.max = _G.math.max
Grichelde.functions.min = _G.math.min
Grichelde.F = {
IsAddOnLoaded = _G.IsAddOnLoaded,
assert = _G.assert,
type = _G.type,
print = _G.print,
nilOrEmpty = nilOrEmpty,
pairs = _G.pairs,
ipairs = _G.ipairs,
spairs = spairs,
tContains = _G.tContains,
tFilter = tFilter,
tInsert = _G.table.insert,
tConcat = _G.table.concat,
tSize = tSize,
tIsEmpty = tIsEmpty,
tSort = _G.table.sort,
tClone = tClone,
tNext = _G.next,
tWipe = _G.wipe,
setmetatable = _G.setmetatable,
getmetatable = _G.getmetatable,
select = _G.select,
unpack = _G.unpack,
find = _G.string.find,
sub = _G.string.sub,
gsub = _G.string.gsub,
match = _G.strmatch,
gmatch = _G.string.gmatch,
join = _G.strjoin,
split = _G.strsplit,
toUpper = _G.strupper,
toLower = _G.strlower,
getNextCharUtf8 = getNextCharUtf8,
isLetter = isLetter,
isNumber = isNumber,
isUpper = isUpper,
isLower = isLower,
isCapital = isCapital,
capitalize = capitalize,
color = color,
cPrefix = cPrefix,
cYellow = cYellow,
cGray = cGray,
cDarkgray = cDarkgray,
cGreen = cGreen,
cOrange = cOrange,
cRed = cRed,
toByte = _G.string.byte,
bytes2Char = _G.string.char,
format = _G.string.format,
rep = _G.string.rep,
trim = _G.strtrim,
length = _G.string.len,
lengthUtf8 = _G.strlenutf8,
toString = _G.tostring,
toNumber = _G.tonumber,
max = _G.math.max,
min = _G.math.min,
}