Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ Functions

Functions

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Fadedparadox   USA  (91 posts)  Bio
Date Thu 25 Jun 2009 05:16 PM (UTC)

Amended on Thu 25 Jun 2009 05:23 PM (UTC) by Fadedparadox

Message
Here are a couple of functions I've made in Lua, I hope some come in handy:

ansicolor

For use in AnsiNote, this function returns the ANSI background and foreground colors for you, all you need to specify is the number(s) (0-15).

Example: AnsiNote (ansicolor (11, 2), "Yellow on green text")

ansicolor = function (fore, back)
  local bold = false
  local fore = tonumber (fore) or 7
  if fore >= 0 and fore <= 7 then
    fore = fore + 30
  elseif fore >= 8 and fore <= 15 then
    fore = fore + 22
    bold = true
  else
    fore = 37
  end -- if
  local back = tonumber (back) or 0
  if back > 0 and back <= 7 then
    back = back + 40
  else
    back = 40
  end -- if
  if not bold then
    return ANSI (0, fore, back)
  else
    return ANSI (0, fore, 1, back)
  end -- if
end -- func


colorchart

This function display a color chart for ease in deciding on a fore/background combination. Just call it with colorchart (). You can also include two parameters, the first being 'fore' or 'back' and the second the specific fore or back color you want to limit it by, and it will display all combinations for that specific color. Requires ansicolor.

colorchart = function (x, y)
  if x == "fore" then
    if y and y >= 0 and y <= 15 then
      local fore = y
      for back = 0, 7 do
        AnsiNote (ansicolor (fore, back), string.format (" Fore: %-2s Back: %s ", fore, back))
      end -- for
    else
      for fore = 0, 15 do for back = 0, 7 do
        AnsiNote (ansicolor (fore, back), string.format (" Fore: %-2s Back: %s ", fore, back))
      end end -- for
    end -- if
  else
    if y and y >= 0 and y <= 7 then
      local back = tonumber(y)
      for fore = 0, 15 do
        AnsiNote (ansicolor (fore, back), string.format (" Fore: %-2s Back: %s ", fore, back))
      end -- for
    else
      for back = 0, 7 do for fore = 0, 15 do
        AnsiNote (ansicolor (fore, back), string.format (" Fore: %-2s Back: %s ", fore, back))
      end end -- for
    end -- if
  end -- if
end -- func


getcolor

This function gets the current rgb version of your ANSI color from your settings. Call it with getcolor (#) where # is between 0 and 15. Returns false if you choose something outside that range.

getcolor = function (x)
  local func
  if x >= 0 and x <= 7 then
    x = x + 1
    func = GetNormalColour
  elseif x >= 8 and x <= 15 then
    x = x - 7
    func = GetBoldColour
  else
    func = function () return false end
  end
  return func (x)
end -- func


string.proper

Like string.upper and string.lower, this returns the proper case (first is capitalized, rest is lowercase) version of a string.

string.proper = function (x)
  return string.upper (string.sub(x, 1, 1)) .. string.lower (string.sub(x, 2))
end -- func

Top

Posted by Fadedparadox   USA  (91 posts)  Bio
Date Reply #1 on Thu 25 Jun 2009 05:28 PM (UTC)
Message
Oh and for the colorchart, colorchart ("fore") will sort it by foreground color instead of the default, background.
Top

Posted by Nick Gammon   Australia  (23,162 posts)  Bio   Forum Administrator
Date Reply #2 on Thu 25 Jun 2009 09:10 PM (UTC)

Amended on Thu 25 Jun 2009 09:11 PM (UTC) by Nick Gammon

Message

That looks nice, thanks for releasing it.

The colorchar output looks like this:

This lists all the combinations of the ANSI colours as foreground and background combinations (this would be useful for MUD admins deciding on a colour scheme).


By the way, if you want to see what all the named RGB colours look like, you can type: /Debug 'colours'


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Fadedparadox   USA  (91 posts)  Bio
Date Reply #3 on Thu 25 Jun 2009 10:07 PM (UTC)

Amended on Thu 25 Jun 2009 10:08 PM (UTC) by Fadedparadox

Message
I mostly use colorchart for deciding on output colors, since it's hard for me to picture what color combinations go well together.

The getcolor function I use to make matches that I can't use regex for, but are colored specifically. I just test to textcolour and backcolour from TriggerStyleRuns.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


15,266 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.