ColorAll

From Mudlet
Revision as of 23:09, 29 July 2011 by Phoenix (talk | contribs) (Created page with "This function was made by ThePhoenix in conjunction with Keneanung. It works to highlight all of 'word' on a line. <lua> function colorAll(word, color, back, it...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function was made by ThePhoenix in conjunction with Keneanung. It works to highlight all of 'word' on a line.

<lua> 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(line, "%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 </lua>

Api will be written after the IRE Great Hunt.