Module: DTC::Utils::Text::ANSI
- Defined in:
- lib/dtc/utils/text/ansi.rb
Constant Summary collapse
- DISPLAY_ATTRIBUTES =
({ :reset => 0, :bold => 1, :underline => 4, :reverse => 7, :black => 30, :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36, :white => 37, :bg_black => 40, :bg_red => 41, :bg_green => 42, :bg_yellow => 43, :bg_blue => 44, :bg_magenta => 45, :bg_cyan => 46, :bg_white => 47, })
Class Method Summary collapse
Class Method Details
.coloured_string(*att_text) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dtc/utils/text/ansi.rb', line 31 def self.coloured_string *att_text if att_text.last.is_a?(FalseClass) att_text.pop else unless (att_text.select { |e| e.is_a?(Symbol) }.last == :reset) att_text.push :reset end end att_text.map { |t| t.is_a?(String) ? t : escape_for_display_attributes(*Array(t)) }.join("") end |
.escape_for_display_attributes(*attrs) ⇒ Object
28 29 30 |
# File 'lib/dtc/utils/text/ansi.rb', line 28 def self.escape_for_display_attributes *attrs "\033[#{attrs.map { |e| DISPLAY_ATTRIBUTES[e] || e}.join(";")}m" end |