Class: String
Constant Summary collapse
- @@print_with_attributes =
true
Class Method Summary collapse
Instance Method Summary collapse
-
#att(a = :default) ⇒ Object
See colour.
-
#bgcolour(bgcol = :default) ⇒ Object
(also: #bgcolor)
See colour.
-
#bright ⇒ Object
Shortcut for att(:bright).
-
#colour(col, bgcol = nil, attribute = nil) ⇒ Object
(also: #color)
col
,bgcol
, andattribute
are symbols corresponding to Console::COLOURS, Console::BGCOLOURS, and Console::ATTRIBUTES. -
#noatt ⇒ Object
(also: #noansi)
Returns the string with ANSI escape codes removed.
-
#print_at(x = nil, y = nil, minus = false) ⇒ Object
Print the string at
x
y
.
Class Method Details
.disable_color ⇒ Object
5 |
# File 'lib/drydock/mixins/string.rb', line 5 def String.disable_color; @@print_with_attributes = false; end |
.disable_colour ⇒ Object
4 |
# File 'lib/drydock/mixins/string.rb', line 4 def String.disable_colour; @@print_with_attributes = false; end |
Instance Method Details
#att(a = :default) ⇒ Object
See colour
33 34 35 36 37 38 |
# 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) ⇒ Object Also known as: bgcolor
See colour
24 25 26 27 28 29 |
# 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 |
#bright ⇒ Object
Shortcut for att(:bright)
41 |
# File 'lib/drydock/mixins/string.rb', line 41 def bright; att(:bright); end |
#colour(col, bgcol = nil, attribute = nil) ⇒ Object Also known as: color
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"
15 16 17 18 19 20 |
# 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 |
#noatt ⇒ Object Also known as: noansi
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
61 62 63 |
# File 'lib/drydock/mixins/string.rb', line 61 def noatt gsub(/\e\[?[0-9;]*[mc]?/, '') end |
#print_at(x = nil, y = nil, minus = false) ⇒ Object
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.
46 47 48 49 50 51 |
# 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 |