Module: Autumn::Formatting::Mirc

Defined in:
lib/autumn/formatting.rb

Overview

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}!"

Constant Summary collapse

PLAIN =

Insert this character to set all following text unformatted.

15.chr
BOLD =

Insert this character to set all following text bolded.

2.chr
ITALIC =

Insert this character to set all following text italicized.

22.chr
UNDERLINE =

Insert this character to set all following text underlined.

31.chr
COLOR_CODE =

The mIRC color code sentinel.

3.chr
UNCOLOR =

Insert this character to stop colorizing text.

COLOR_CODE + " "
UNCOLOR_NO_SPACE =

Same as UNCOLOR, but suppresses the trailing space for situations where no conflict is assured.

COLOR_CODE
COLORS =

Valid IRC colors, in the mIRC style, to be used with the color method.

{
  :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'
}

Instance Method Summary collapse

Instance Method Details

#boldObject

Sets all following text bold.



115
# File 'lib/autumn/formatting.rb', line 115

def bold; BOLD; end

#color(fgcolor, bgcolor = nil, options = {}) ⇒ Object

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.



105
106
107
108
109
# File 'lib/autumn/formatting.rb', line 105

def color(fgcolor, bgcolor=nil, options={})
  fgcolor = :black unless COLORS.include? fgcolor
  bgcolor = :white unless (bgcolor.nil? or COLORS.include? bgcolor)
  "#{COLOR_CODE}#{COLORS[fgcolor]}#{bgcolor ? (',' + COLORS[bgcolor]) : ''}#{options[:suppress_space] ? '' : ' '}"
end

#italicObject

Sets all following text italic.



118
# File 'lib/autumn/formatting.rb', line 118

def italic; ITALIC; end

#plainObject

Sets all following text unformatted.



112
# File 'lib/autumn/formatting.rb', line 112

def plain; PLAIN; end

#uncolor(options = {}) ⇒ Object

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.



128
129
130
# File 'lib/autumn/formatting.rb', line 128

def uncolor(options={})
  options[:suppress_space] ? UNCOLOR_NO_SPACE : UNCOLOR
end

#underlineObject

Sets all following text underline.



121
# File 'lib/autumn/formatting.rb', line 121

def underline; UNDERLINE; end