[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Functions

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Functions
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Fadedparadox   USA  (91 posts)  [Biography] bio
Date Thu 25 Jun 2009 10:07 PM (UTC)  quote  ]

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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Thu 25 Jun 2009 09:10 PM (UTC)  quote  ]

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
[Go to top] top

Posted by Fadedparadox   USA  (91 posts)  [Biography] bio
Date Thu 25 Jun 2009 05:28 PM (UTC)  quote  ]
Message
Oh and for the colorchart, colorchart ("fore") will sort it by foreground color instead of the default, background.
[Go to top] top

Posted by Fadedparadox   USA  (91 posts)  [Biography] bio
Date Thu 25 Jun 2009 05:16 PM (UTC)  quote  ]

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

[Go to top] 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.


1,845 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]