Difference between revisions of "ColorAll"
Jump to navigation
Jump to search
m |
|||
Line 1: | Line 1: | ||
This function was made by [[user:phoenix|ThePhoenix]] in conjunction with Keneanung. It works to highlight all of 'word' on a line. | This function was made by [[user:phoenix|ThePhoenix]] in conjunction with Keneanung. It works to highlight all of 'word' on a line. | ||
− | <lua> | + | <syntaxhighlight lang="lua"> |
function colorAll(word, color, back, italic, under,bold, noCase) | function colorAll(word, color, back, italic, under,bold, noCase) | ||
--word is the string to search for | --word is the string to search for | ||
Line 45: | Line 45: | ||
end | end | ||
end | end | ||
− | </ | + | </syntaxhighlight> |
[[Category:Snippets]] | [[Category:Snippets]] |
Revision as of 23:50, 18 January 2024
This function was made by ThePhoenix in conjunction with Keneanung. It works to highlight all of 'word' on a line.
function colorAll(word, color, back, italic, under,bold, noCase)
--word is the string to search for
--color is fg color, either in name or "r,g,b" string
--back is bg color, either in name of "r,g,b" string
--italic is boolean italics
--under is boolean underlining
--bold is boolean bold format
--noCase is boolean. if true, matches word on a no-case pattern
if noCase then word = word:genNocasePattern() end
local startpos = 0
local endpos = 0
while true do
startpos, endpos = string.find(getCurrentLine(), "%f[%w]"..word.."%f[%W]", endpos)
if not startpos then break end
selectSection(startpos-1, endpos-startpos+1)
if color then
if color_table[color] then
fg(color)
else
local c = color:split(",")
setFgColor(c[1],c[2],c[3])
end
end
if back then
if color_table[back] then
bg(back)
else
local b = back:split(",")
setBgColor(b[1],b[2],b[3])
end
end
if under then
setUnderline(true)
end
if italic then
setItalics(true)
end
if bold then
setBold(true)
end
end
end