Class: Fhlow::Pen
- Inherits:
-
Object
- Object
- Fhlow::Pen
- Includes:
- Term::ANSIColor
- Defined in:
- lib/module_fhlow/pen.rb
Overview
The class Pen is a wrapper to the standard output function from IO. It is able to add colors to the output by mixing in the module Term::ANSIColor from rubyforge. It also adds a border to the output with a header (Pen.welcome) and a footer (Pen.bye).
Constant Summary
Constants included from Term::ANSIColor
Term::ANSIColor::COLORED_REGEXP
Instance Method Summary collapse
-
#footer(_msg = "work done!") ⇒ Object
Prints the footer.
-
#header(_msg = "fhlow - fast handling of a lot of work") ⇒ Object
Prints the header.
-
#initialize(_outstream, _coloring, _prefix = lightblue+"| "+clear, _width = 80) ⇒ Pen
constructor
Initializes the members.
-
#nl ⇒ Object
Prints a newline without adding the prefix.
-
#noColor ⇒ Object
Turns colors off.
-
#print(*_strings) ⇒ Object
Behaves like IO.print but adds the prefix to each line.
-
#puts(*_strings) ⇒ Object
Behaves like IO.puts but adds the prefix to each line.
-
#seperator(_color = lightblue) ⇒ Object
Prints a seperator line.
Methods included from Term::ANSIColor
attributes, coloring=, coloring?, #uncolored
Constructor Details
#initialize(_outstream, _coloring, _prefix = lightblue+"| "+clear, _width = 80) ⇒ Pen
Initializes the members.
_outstream
-
The IO obejct to be used for output.
_coloring
-
Set to
true
for colorful output orfalse
for no colors. _prefix
-
This is the prefix that will be added in front of every line.
_width
-
The width of the border in amount of characters.
41 42 43 44 45 46 47 48 |
# File 'lib/module_fhlow/pen.rb', line 41 def initialize(_outstream, _coloring, _prefix=lightblue+"| "+clear, _width=80) @@coloring = _coloring @outstream = _outstream @prefix = Hash.new @prefix[true] = _prefix @prefix[false] = uncolored(_prefix) @width = _width end |
Instance Method Details
#footer(_msg = "work done!") ⇒ Object
Prints the footer.
_msg
-
The message inside the footer.
72 73 74 75 76 77 |
# File 'lib/module_fhlow/pen.rb', line 72 def (_msg="work done!") @width = _msg.length+2 if _msg.length > @width @outstream.print lightblue, "+", "-"*@width, "+\n", clear @outstream.print lightblue, "| ", clear, _msg.center(@width-2), lightblue, " |\n", clear @outstream.print lightblue, "`", "-"*@width, "+\n", clear end |
#header(_msg = "fhlow - fast handling of a lot of work") ⇒ Object
Prints the header.
_msg
-
The message inside the header.
57 58 59 60 61 62 |
# File 'lib/module_fhlow/pen.rb', line 57 def header(_msg="fhlow - fast handling of a lot of work") @width = _msg.length+2 if _msg.length > @width @outstream.print lightblue, ",", "-"*@width, "+\n", clear @outstream.print lightblue, "| ", clear, _msg.center(@width-2), lightblue, " |\n", clear @outstream.print lightblue, "+", "-"*@width, "+\n", clear end |
#nl ⇒ Object
Prints a newline without adding the prefix.
80 81 82 |
# File 'lib/module_fhlow/pen.rb', line 80 def nl @outstream.print "\n" end |
#noColor ⇒ Object
Turns colors off.
51 52 53 |
# File 'lib/module_fhlow/pen.rb', line 51 def noColor @@coloring = false end |
#print(*_strings) ⇒ Object
Behaves like IO.print but adds the prefix to each line.
*_strings
-
An Array of objects that will be passed to IO.print.
86 87 88 89 |
# File 'lib/module_fhlow/pen.rb', line 86 def print(*_strings) _strings.each { |s| s.gsub!(/\n(?!\z)/, "\n"+lightblue+"| "+clear) } @outstream.print @prefix[@@coloring], _strings end |
#puts(*_strings) ⇒ Object
Behaves like IO.puts but adds the prefix to each line.
*_strings
-
An Array of objects that will be passed to IO.puts.
93 94 95 96 |
# File 'lib/module_fhlow/pen.rb', line 93 def puts(*_strings) _strings.each { |s| s.gsub!(/\n(?!\z)/, "\n"+lightblue+"| "+clear) } @outstream.puts @prefix[@@coloring]+_strings.join end |
#seperator(_color = lightblue) ⇒ Object
Prints a seperator line.
_color
-
The color of the line.
66 67 68 |
# File 'lib/module_fhlow/pen.rb', line 66 def seperator(_color=lightblue) @outstream.print _color, "+", "-"*@width, "+\n", clear end |