ColorAll

From Mudlet
Revision as of 00:30, 19 January 2024 by Zooka (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Game non-mud specific
By ThePhoenix in conjunction with Keneanung
Download none
Dependencies Mudlet 4.17

Description

It works to highlight all of 'word' on a line.

Usage

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