Module: Console::Colors
- Defined in:
- lib/jarl/console.rb
Overview
module Utils
Constant Summary collapse
- SEQUENCE =
%w(31 32 33 34 35 36 37 31;1 32;1 33;1 34;1 35;1 36;1 37;1)
Instance Method Summary collapse
-
#esc_blue(text) ⇒ Object
Returns ANSI escaped string for the blue colored text.
-
#esc_bold(text) ⇒ Object
Returns ANSI escaped string for the bold text.
-
#esc_color(color_code, text) ⇒ Object
Returns ANSI escaped string for the colored text.
-
#esc_format(*args) ⇒ Object
Returns string with formatted and padded fields Each arg is an Array: [<text>, [padding_num], [color]].
-
#esc_green(text) ⇒ Object
Returns ANSI escaped string for the green colored text.
-
#esc_pad(text, num, color = nil) ⇒ Object
Returns string padded to given number of characters, text can be escaped.
-
#esc_red(text) ⇒ Object
Returns ANSI escaped string for the red colored text.
-
#esc_string(esc, text) ⇒ Object
Returns ANSI escaped string.
-
#esc_yellow(text) ⇒ Object
Returns ANSI escaped string for the yellow colored text.
Instance Method Details
#esc_blue(text) ⇒ Object
Returns ANSI escaped string for the blue colored text.
61 62 63 |
# File 'lib/jarl/console.rb', line 61 def esc_blue(text) esc_color 34, text end |
#esc_bold(text) ⇒ Object
Returns ANSI escaped string for the bold text.
67 68 69 |
# File 'lib/jarl/console.rb', line 67 def esc_bold(text) esc_string "\e[01;37m", text end |
#esc_color(color_code, text) ⇒ Object
Returns ANSI escaped string for the colored text.
37 38 39 |
# File 'lib/jarl/console.rb', line 37 def esc_color(color_code, text) esc_string "\e[#{color_code}m", text end |
#esc_format(*args) ⇒ Object
Returns string with formatted and padded fields Each arg is an Array:
- <text>, [padding_num], [color]
87 88 89 90 91 92 93 |
# File 'lib/jarl/console.rb', line 87 def esc_format(*args) out = [] args.each do |arg| out << esc_pad(arg[0], arg[1] || 0, arg[2]) end out.join(' ') end |
#esc_green(text) ⇒ Object
Returns ANSI escaped string for the green colored text.
49 50 51 |
# File 'lib/jarl/console.rb', line 49 def esc_green(text) esc_color 32, text end |
#esc_pad(text, num, color = nil) ⇒ Object
Returns string padded to given number of characters, text can be escaped.
73 74 75 76 77 78 79 80 81 |
# File 'lib/jarl/console.rb', line 73 def esc_pad(text, num, color = nil) esc_text = text case color when :red, :yellow, :green esc_text = send :"esc_#{color}", text end pad = esc_text.size - text.size num > 0 ? ("%-#{num + pad}s" % esc_text) : esc_text end |
#esc_red(text) ⇒ Object
Returns ANSI escaped string for the red colored text.
43 44 45 |
# File 'lib/jarl/console.rb', line 43 def esc_red(text) esc_color 31, text end |
#esc_string(esc, text) ⇒ Object
Returns ANSI escaped string.
31 32 33 |
# File 'lib/jarl/console.rb', line 31 def esc_string(esc, text) esc + text.to_s + "\e[0m" end |
#esc_yellow(text) ⇒ Object
Returns ANSI escaped string for the yellow colored text.
55 56 57 |
# File 'lib/jarl/console.rb', line 55 def esc_yellow(text) esc_color 33, text end |