Difference between revisions of "ColorAll"

From Mudlet
Jump to navigation Jump to search
(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...")
 
 
(3 intermediate revisions by 3 users not shown)
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.
+
[[Category:Mudlet Package Listing]]
 +
{| class="wikitable" style="width: 70%;"
 +
|-
 +
| style="width: 10%" | Game || non-mud specific
 +
|-
 +
| By || [[user:phoenix|ThePhoenix]] in conjunction with Keneanung
 +
|-
 +
| Download || none
 +
|-
 +
| Dependencies || <!-- any package dependencies|mudlet version requirements --> Mudlet 4.17
 +
|}
  
<lua>
+
= Description = 
 +
<!-- A description about what your script accomplishes. -->
 +
 
 +
It works to highlight all of 'word' on a line.
 +
 
 +
= Usage =
 +
 
 +
<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 15: Line 32:
 
   local endpos = 0
 
   local endpos = 0
 
   while true do
 
   while true do
       startpos, endpos = string.find(line, "%f[%w]"..word.."%f[%W]", endpos)
+
       startpos, endpos = string.find(getCurrentLine(), "%f[%w]"..word.."%f[%W]", endpos)
 
       if not startpos then break end
 
       if not startpos then break end
 
       selectSection(startpos-1, endpos-startpos+1)
 
       selectSection(startpos-1, endpos-startpos+1)
Line 45: Line 62:
 
   end
 
   end
 
end
 
end
</lua>
+
</syntaxhighlight>
 
 
Api will be written after the IRE Great Hunt.
 

Latest revision as of 00:30, 19 January 2024

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