Module: StillActive::AnsiHelper
Constant Summary collapse
- RESET =
"\e[0m"- ANSI_PATTERN =
/\e\[[0-9;]*m/
Instance Method Summary collapse
- #bold(text) ⇒ Object
- #dim(text) ⇒ Object
- #green(text) ⇒ Object
- #pad(text, width) ⇒ Object
- #red(text) ⇒ Object
- #visible_length(text) ⇒ Object
- #yellow(text) ⇒ Object
Instance Method Details
#bold(text) ⇒ Object
14 |
# File 'lib/helpers/ansi_helper.rb', line 14 def bold(text) = "\e[1m#{text}#{RESET}" |
#dim(text) ⇒ Object
13 |
# File 'lib/helpers/ansi_helper.rb', line 13 def dim(text) = "\e[2m#{text}#{RESET}" |
#green(text) ⇒ Object
10 |
# File 'lib/helpers/ansi_helper.rb', line 10 def green(text) = "\e[32m#{text}#{RESET}" |
#pad(text, width) ⇒ Object
20 21 22 23 |
# File 'lib/helpers/ansi_helper.rb', line 20 def pad(text, width) padding = width - visible_length(text) padding > 0 ? "#{text}#{" " * padding}" : text end |
#red(text) ⇒ Object
12 |
# File 'lib/helpers/ansi_helper.rb', line 12 def red(text) = "\e[31m#{text}#{RESET}" |
#visible_length(text) ⇒ Object
16 17 18 |
# File 'lib/helpers/ansi_helper.rb', line 16 def visible_length(text) text.gsub(ANSI_PATTERN, "").length end |
#yellow(text) ⇒ Object
11 |
# File 'lib/helpers/ansi_helper.rb', line 11 def yellow(text) = "\e[33m#{text}#{RESET}" |