class String
Public Class Methods
disable_color()
click to toggle source
# File lib/drydock/mixins/string.rb, line 5 def String.disable_color; @@print_with_attributes = false; end
disable_colour()
click to toggle source
# File lib/drydock/mixins/string.rb, line 4 def String.disable_colour; @@print_with_attributes = false; end
enable_color()
click to toggle source
# File lib/drydock/mixins/string.rb, line 7 def String.enable_color; @@print_with_attributes = true; end
enable_colour()
click to toggle source
# File lib/drydock/mixins/string.rb, line 6 def String.enable_colour; @@print_with_attributes = true; end
Public Instance Methods
att(a = :default)
click to toggle source
See colour
# File lib/drydock/mixins/string.rb, line 33 def att(a = :default) return self unless @@print_with_attributes Console.style(nil, nil, a) + self + Console.style(nil, nil, :default) end
bgcolour(bgcol = :default)
click to toggle source
See colour
# File lib/drydock/mixins/string.rb, line 24 def bgcolour(bgcol = :default) return self unless @@print_with_attributes Console.style(nil, bgcol, nil) + self + Console.style(nil, :default, nil) end
Also aliased as: bgcolor
bright()
click to toggle source
Shortcut for att(:bright)
# File lib/drydock/mixins/string.rb, line 41 def bright; att(:bright); end
colour(col, bgcol = nil, attribute = nil)
click to toggle source
col
, bgcol
, and attribute
are
symbols corresponding to Console::COLOURS, Console::BGCOLOURS, and
Console::ATTRIBUTES. Returns the string in the format attributes + string +
defaults.
"MONKEY_JUNK".colour(:blue, :white, :blink) # => "\e[34;47;5mMONKEY_JUNK\e[39;49;0m"
# File lib/drydock/mixins/string.rb, line 15 def colour(col, bgcol = nil, attribute = nil) return self unless @@print_with_attributes Console.style(col, bgcol, attribute) + self + Console.style(:default, :default, :default) end
Also aliased as: color
noatt()
click to toggle source
Returns the string with ANSI escape codes removed.
NOTE: The non-printable attributes count towards the string size. You can use this method to get the “visible” size:
"\e[34;47;5mMONKEY_JUNK\e[39;49;0m".noatt.size # => 11 "\e[34;47;5mMONKEY_JUNK\e[39;49;0m".size # => 31
# File lib/drydock/mixins/string.rb, line 61 def noatt gsub(/\e\[?[0-9;]*[mc]?/, '') end
Also aliased as: noansi
print_at(x=nil, y=nil, minus=false)
click to toggle source
Print the string at x
y
. When minus
is any true value the length of the string is subtracted from the value of
x before printing.
# File lib/drydock/mixins/string.rb, line 46 def print_at(x=nil, y=nil, minus=false) args = {:minus=>minus} args[:x] &&= x args[:y] &&= y Console.print_at(self, args) end