Not built-in, and not the way you wanted to do it, no. There's still the virtualized trigger I suggested before; in fact I wrote and tested it already last night. I was going to finish my stylestring implementation before posting it, but why not:
stylestring = {}
function stylestring.new(str, styles)
return setmetatable({
str = str,
styles = styles,
}, {
__index = stylestring,
})
end
function stylestring.tell(self)
local str, styles = self.str, self.styles
local left = 1
for _,t in pairs(styles) do
local fg = RGBColourToName(t.textcolour)
local bg = RGBColourToName(t.backcolour)
ColourTell(fg, bg, str:sub(left, left + t.length - 1))
left = left + t.length
end
end
function stylestring.note(self)
self:tell()
AnsiNote() -- not sure if Note() preserves the current color, but I know this does
end
function stylestring.replace(self, match, replace)
-- TODO: Stretch/shrink styles as needed.
-- Until then, this is a glorified gsub.
local str = self.str
local match_len = match:len()
local left = 1
local mid = str:find(match)
while mid do
if left then
str = str:sub(left, mid-1) .. replace .. str:sub(mid + match_len)
left = mid + match_len
end
mid = str:find(match, left)
end
self.str = str
return self
end
local subs = {}
function add_sub(match, replace)
table.insert(subs, {
match = match,
replace = replace,
});
end
function do_sub(str)
for _,t in ipairs(subs) do
str = str:replace(t.match, t.replace)
end
return str
end
function get_subs()
return subs
end
<triggers>
<trigger
enabled="y"
ignore_case="y"
keep_evaluating="y"
match="^.*$"
omit_from_output="y"
regexp="y"
send_to="14"
sequence="100"
>
<send>local str = stylestring.new("%0", TriggerStyleRuns)
do_sub(str):note()</send>
</trigger>
</triggers>
<aliases>
<alias
match="^\s*#sub\s*{((?:[^}]|\})+)}\s*{((?:[^}]|\})+)}\s*$"
enabled="y"
omit_from_log="y"
regexp="y"
send_to="12"
omit_from_output="y"
ignore_case="y"
sequence="100"
>
<send>add_sub(("%1"):gsub("\\}", "}"), ("%2"):gsub("\\}", "}"))</send>
</alias>
</aliases>
|