diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-08-29 19:48:18 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-08-29 19:48:18 +0000 |
commit | 17d1d6ec370313dbf0e49681241049e8c6fe0717 (patch) | |
tree | 3e63f53a0e73f10848df6f8aeef733f58e6cc4fa /lib/rbot | |
parent | 5e26385a85bd6d71af5250973a0201b1f9860c5a (diff) |
Color codes and Irc.color(fg, bg) methods to ease color display
Diffstat (limited to 'lib/rbot')
-rw-r--r-- | lib/rbot/core/utils/extends.rb | 73 | ||||
-rw-r--r-- | lib/rbot/message.rb | 7 |
2 files changed, 73 insertions, 7 deletions
diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb index e0c781b1..31a348a9 100644 --- a/lib/rbot/core/utils/extends.rb +++ b/lib/rbot/core/utils/extends.rb @@ -227,6 +227,79 @@ end module ::Irc + # Define standard IRC attriubtes (not so standard actually, + # but the closest thing we have ...) + Bold = "\002" + Underline = "\037" + Reverse = "\026" + Italic = "\011" + NormalText = "\017" + + # Color is prefixed by \003 and followed by optional + # foreground and background specifications, two-digits-max + # numbers separated by a comma. One of the two parts + # must be present. + Color = "\003" + ColorRx = /#{Color}\d?\d?(?:,\d\d?)?/ + + # Standard color codes + ColorCode = { + :black => 1, + :blue => 2, + :navyblue => 2, + :navy_blue => 2, + :green => 3, + :red => 4, + :brown => 5, + :purple => 6, + :olive => 7, + :yellow => 8, + :limegreen => 9, + :lime_green => 9, + :teal => 10, + :aqualight => 11, + :aqua_light => 11, + :royal_blue => 12, + :hotpink => 13, + :hot_pink => 13, + :darkgray => 14, + :dark_gray => 14, + :lightgray => 15, + :light_gray => 15, + :white => 16 + } + + # Convert a String or Symbol into a color number + def Irc.find_color(data) + if Integer === data + data + else + f = if String === data + data.intern + else + data + end + if ColorCode.key?(f) + ColorCode[f] + else + 0 + end + end + end + + # Insert the full color code for a given + # foreground/background combination. + def Irc.color(fg=nil,bg=nil) + str = Color.dup + if fg + str << Irc.find_color(fg).to_s + end + if bg + str << "," << Irc.find_color(bg).to_s + end + return str + end + class BasicUserMessage diff --git a/lib/rbot/message.rb b/lib/rbot/message.rb index 192e02f1..75427a9e 100644 --- a/lib/rbot/message.rb +++ b/lib/rbot/message.rb @@ -14,13 +14,6 @@ module Irc :desc => "when replying with nick put this character after the nick of the user the bot is replying to" ) - Bold = "\002" - Underline = "\037" - Reverse = "\026" - Italic = "\011" - Color = "\003" - ColorRx = /#{Color}\d?\d?(?:,\d\d?)?/ - # base user message class, all user messages derive from this # (a user message is defined as having a source hostmask, a target # nick/channel and a message part) |