Mudlet SEARCHNEWS Highlighter

Hey all,

I made the below alias to assist with finding things when looking at old news. It basically just augments the SEARCHNEWS command in-game to remember what you search for, then later highlight any occurrence of that word or phrase. I didn't want things scattered around too much between aliases/triggers/scripts, so everything is self-contained in the alias. Once everything is in place and working, you can SEARCHNEWS CLEAR HIGHLIGHT to clear any existing highlight you've got set.

Here's a sample of the output: SEARCHNEWS Command Output

  1. Create a new Alias in Mudlet, give it a good name such as "I love Malaphus" or "SEARCHNEWS", etc.
  2. Paste the following into the PATTERN textbox:
    (?i)^\s*searchnews(?: ([a-zA-Z]+))(?: ([ASB]))?(?: ([0-9]+))?(.+)
  3. Paste the following into the script area:
    --
    -- Author: Malaphus
    --
    
    -- Settings:
    local searchHighlightColor = "yellow"
    
    
    -- END Settings.  Don't edit things below this line unless you know how to not break stuff.
    
    lastNewsSearch = matches[5]:trim():lower()
    
    if matches[2] == "clear" and lastNewsSearch == "highlight" then
      if newsHighlightTrigger then
        cecho("Searchnews highlight has been cleared.\n")
        killTrigger(newsHighlightTrigger)
        newsHighlightTrigger = nil
      else
        cecho("Searchnews highlight has was not set.\n")
      end
      send("\n", false)
      return
    end
    
    newsHighlightFunction = newsHighlightFunction or function (term, color)
      local c, k = 1, 1
      while k > 0 do
        k = line:lower():find(term, k)
        if k == nil then
          return
        end
        c = c + 1
    
        from, how_long = line:lower():find("%f[%a]"..term.."%f[%A]", k)
        if from then
          if selectSection(k-1, how_long - k + 1) then
            fg(color)
            resetFormat()
          else return end
        end
    
        k = from + 1
      end
    end
    
    if newsHighlightTrigger then
      killTrigger(newsHighlightTrigger)
      newsHighlightTrigger = nil
    end
    
    newsHighlightTrigger = tempRegexTrigger("(?i:" .. lastNewsSearch .. ")", ([[newsHighlightFunction("%s", "%s")]]):format(lastNewsSearch, searchHighlightColor))
    
    send(matches[1], false)
    
    cecho("\nSearch Term: <" .. searchHighlightColor .. ">" .. lastNewsSearch .. "\n\nSearch Results:\n\n")
    

    I hope other people find it useful!

    -Malaphus

Comments

  • Can I get a picture of it working so I don't have to install it just to see what it looks like or what it's doing?
    Thanks!
  • Nylian said:
    Can I get a picture of it working so I don't have to install it just to see what it looks like or what it's doing?
    Thanks!
    There is a link in the post! 
  • edited January 2016
    Dairon said:
    Nylian said:
    Can I get a picture of it working so I don't have to install it just to see what it looks like or what it's doing?
    Thanks!
    There is a link in the post! 
    Oh! I like it! Nice job!!
  • Something up with the pattern.
    Have to put two spaces after the news section I'm looking in;

    searchnews announce bullet

    Search Term: ullet

    Search Results:

       Article Author                         Subject                              
    -------------------------------------------------------------------------------
          2719 Maya, the Great Mother         In progress
          1570 Sarapis, the Logos             BFU - Big F*cking Upgrade
    -------------------------------------------------------------------------------
    -- #######
    searchnews announce  bullet

    Search Term: bullet

    Search Results:

       Article Author                         Subject                              
    -------------------------------------------------------------------------------
          2719 Maya, the Great Mother         In progress
          1570 Sarapis, the Logos             BFU - Big F*cking Upgrade
  • edited January 2016
    UPDATE:

    1. Create a new Alias in Mudlet, give it a good name such as "I love Malaphus" or "SEARCHNEWS", etc.
    2. Paste the following into the PATTERN textbox:
      (?i)^\s*searchnews(?: ([a-zA-Z]+))(?: ([ASB]) )?(?: ([0-9]+))?(.+)
    3. Paste the following into the script area:
      --
      -- Author: Malaphus
      --
      
      -- Settings:
      local searchHighlightColor = "yellow"
      
      
      -- END Settings.  Don't edit things below this line unless you know how to not break stuff.
      
      lastNewsSearch = matches[5]:trim():lower()
      
      if matches[2] == "clear" and lastNewsSearch == "highlight" then
        if newsHighlightTrigger then
          cecho("Searchnews highlight has been cleared.\n")
          killTrigger(newsHighlightTrigger)
          newsHighlightTrigger = nil
        else
          cecho("Searchnews highlight has was not set.\n")
        end
        send("\n", false)
        return
      end
      
      newsHighlightFunction = newsHighlightFunction or function (term, color)
        local c, k = 1, 1
        while k > 0 do
          k = line:lower():find(term, k)
          if k == nil then
            return
          end
          c = c + 1
      
          from, how_long = line:lower():find("%f[%a]"..term.."%f[%A]", k)
          if from then
            if selectSection(k-1, how_long - k + 1) then
              fg(color)
              resetFormat()
            else return end
          end
      
          k = from + 1
        end
      end
      
      if newsHighlightTrigger then
        killTrigger(newsHighlightTrigger)
        newsHighlightTrigger = nil
      end
      
      newsHighlightTrigger = tempRegexTrigger("(?i:" .. lastNewsSearch .. ")", ([[newsHighlightFunction("%s", "%s")]]):format(lastNewsSearch, searchHighlightColor))
      
      send(matches[1], false)
      
      cecho("\nSearch Term: <" .. searchHighlightColor .. ">" .. lastNewsSearch .. "\n\nSearch Results:\n\n")
      
Sign In or Register to comment.