Module Autumn::Formatting::Mirc
In: libs/formatting.rb

The mIRC format is the oldest IRC text formatting protocol, written for use with the mIRC client. Although mIRC formatting is by far the most common and most widely supported, it is also has the fewest features. mIRC also has some limitations that can occur when coloring text; please see the color method for more information.

To stylize your text, insert the appropriate style code in your text where desired. For example (assuming you have included the Mirc module):

 "I'm feeling #{BOLD}bold today, and #{ITALIC}how#{PLAIN}!"

yields:

I‘m feeling bold today, and how!

To colorize text, you must call the color method, and insert an UNCOLOR token at the end of the colorized text:

 "The system is: #{color(:red)}down#{UNCOLOR}!"

Methods

bold   color   italic   plain   uncolor   underline  

Constants

PLAIN = 15.chr   Insert this character to set all following text unformatted.
BOLD = 2.chr   Insert this character to set all following text bolded.
ITALIC = 22.chr   Insert this character to set all following text italicized.
UNDERLINE = 31.chr   Insert this character to set all following text underlined.
COLOR_CODE = 3.chr   The mIRC color code sentinel.
UNCOLOR = COLOR_CODE + " "   Insert this character to stop colorizing text.
UNCOLOR_NO_SPACE = COLOR_CODE   Same as UNCOLOR, but suppresses the trailing space for situations where no conflict is assured.
COLORS = { :white => '00', :black => '01', :dark_blue => '02', :navy_blue => '02', :dark_green => '03', :red => '04', :brown => '05', :dark_red => '05', :purple => '06', :dark_yellow => '07', :olive => '07', :orange => '07', :yellow => '08', :green => '09', :lime => '09', :dark_cyan => '10', :teal => '10', :cyan => '11', :blue => '12', :royal_blue => '12', :magenta => '13', :pink => '13', :fuchsia => '13', :gray => '14', :light_gray => '15', :silver => '15'   Valid IRC colors, in the mIRC style, to be used with the color method.

Public Instance methods

Sets all following text bold.

[Source]

     # File libs/formatting.rb, line 115
115:       def bold; BOLD; end

Colors the following text with a foreground and background color. Colors are a symbol in the COLORS hash. By default the background is left uncolored. This method returns a string that should be prepended to the text you want to colorize. Append an UNCOLOR token when you wish to end colorization.

Because of limitations in the mIRC color-coding system, a space will be added after the color code (and before any colorized text). Without this space character, it is possible that your text will appear in the wrong color. (This is most likely to happen when colorizing numbers with commas in them, such as "1,160".) If you would like to suppress this space, because you either are sure that your text will be formatted correctly anyway, or you simply don‘t care, you can pass :suppress_space => true to this method.

[Source]

     # File libs/formatting.rb, line 105
105:       def color(fgcolor, bgcolor=nil, options={})
106:         fgcolor = :black unless COLORS.include? fgcolor
107:         bgcolor = :white unless (bgcolor.nil? or COLORS.include? bgcolor)
108:         "#{COLOR_CODE}#{COLORS[fgcolor]}#{bgcolor ? (',' + COLORS[bgcolor]) : ''}#{options[:suppress_space] ? '' : ' '}"
109:       end

Sets all following text italic.

[Source]

     # File libs/formatting.rb, line 118
118:       def italic; ITALIC; end

Sets all following text unformatted.

[Source]

     # File libs/formatting.rb, line 112
112:       def plain; PLAIN; end

Removes coloring from all following text. Options:

suppress_space:By default, this method places a space after the uncolor token to prevent "color bleed." If you would like to suppress this behavior, set this to true.

[Source]

     # File libs/formatting.rb, line 128
128:       def uncolor(options={})
129:         options[:suppress_space] ? UNCOLOR_NO_SPACE : UNCOLOR
130:       end

Sets all following text underline.

[Source]

     # File libs/formatting.rb, line 121
121:       def underline; UNDERLINE; end

[Validate]