isAnsi

Share your scripts and packages with other Mudlet users.
Post Reply
Phoenix
Posts: 92
Joined: Tue Feb 15, 2011 3:23 am

isAnsi

Post by Phoenix »

Was out today, and decided to mess with a function, and get it working just the way I wanted. Now, I can either feed isAnsi a single argument, and it will return 'true' if either foreground or background colour of the selected text matched, or if I feed it two arguments, it will return 'true' if the first one matches the FG, and the second matches the BG. It's nothing special, but if you find yourself doing a lot of 'isAnsiFgColor() and isAnsiBgColor()' or similar logical tests, it can be quite useful!
Code: [show] | [select all] lua
function isAnsi(...)
  args = {...}
  if not args[2] and args[1] then
    if isAnsiFgColor(args[1]) or isAnsiBgColor(args[1]) then
      return true
    else
      return false
    end
  elseif args[2] and not args[3] then
    if isAnsiFgColor(args[1]) and isAnsiBgColor(args[2]) then
      return true
    else
      return false
    end
  else
    error([[isAnsi() improperly used.
Proper usage: isAnsi(fg), isAnsi(bg), or isAnsi(fg, bg)
Note: isAnsi() with just one argument will match if -either- fg or bg matches the argument!]])
  end
end

Post Reply