Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/clive/output.rb

Constant Summary collapse

COLOURS =
{
  "black"   => 0,
  "red"     => 1,
  "green"   => 2,
  "yellow"  => 3,
  "blue"    => 4,
  "magenta" => 5,
  "cyan"    => 6,
  "white"   => 7
}
ATTRIBUTES =
{
  "bold"      => 1,
  "underline" => 4,
  "blink"     => 5,
  "reverse"   => 7
}

Instance Method Summary collapse

Instance Method Details

#clear_coloursObject

Remove any colour codes from a string.



132
133
134
# File 'lib/clive/output.rb', line 132

def clear_colours
  gsub /\e\[?\d\d{0,2}m/, ''
end

#clear_colours!Object

Same as #clear_colours, but modifies string.



137
138
139
# File 'lib/clive/output.rb', line 137

def clear_colours!
  gsub! /\e\[?\d\d{0,2}m/, ''
end

#colour(code) ⇒ Object

Examples:


require 'clive/output'

puts "bold".bold
puts "underline".underline
puts "blink".blink
puts "green".green
puts "red".red
puts "magenta".magenta
puts "yellow".yellow
puts "blue".blue
puts "grey".grey

puts "combo".blue.bold.underline.blink

Parameters:



120
121
122
123
124
# File 'lib/clive/output.rb', line 120

def colour(code)
  r = "\e[#{code}m#{self}"
  r << "\e[0m" unless self[-4..-1] == "\e[0m"
  r
end

#colour!(code) ⇒ Object

Like #colour but modifies the string object.



127
128
129
# File 'lib/clive/output.rb', line 127

def colour!(code)
  replace self.colour(code)
end