Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/cli_class_tool/string.rb
Overview
Extension to the core String class to add colorization support
Constant Summary collapse
- @@is_a_tty =
colorization
nil
Instance Method Summary collapse
-
#blue ⇒ String
Make the string blue.
-
#brown ⇒ String
Make the string brown (yellow).
-
#colorize(color_code) ⇒ String
Colorize the string using ANSI escape codes.
-
#green ⇒ String
Make the string green.
-
#magenta ⇒ String
Make the string magenta.
-
#red ⇒ String
Make the string red.
Instance Method Details
#blue ⇒ String
Make the string blue
39 40 41 |
# File 'lib/cli_class_tool/string.rb', line 39 def blue colorize(34) end |
#brown ⇒ String
Make the string brown (yellow)
33 34 35 |
# File 'lib/cli_class_tool/string.rb', line 33 def brown colorize(33) end |
#colorize(color_code) ⇒ String
Colorize the string using ANSI escape codes
10 11 12 13 14 15 16 17 |
# File 'lib/cli_class_tool/string.rb', line 10 def colorize(color_code) @@is_a_tty = $stdout.isatty() if @@is_a_tty == nil if @@is_a_tty then return "\e[#{color_code}m#{self}\e[0m" else return self end end |
#green ⇒ String
Make the string green
27 28 29 |
# File 'lib/cli_class_tool/string.rb', line 27 def green colorize(32) end |
#magenta ⇒ String
Make the string magenta
45 46 47 |
# File 'lib/cli_class_tool/string.rb', line 45 def magenta colorize(35) end |
#red ⇒ String
Make the string red
21 22 23 |
# File 'lib/cli_class_tool/string.rb', line 21 def red colorize(31) end |