class CLAide::ANSI::StringEscaper
Provides support to wrap strings in ANSI
sequences according to the `ANSI.disabled` setting.
Public Class Methods
new(string)
click to toggle source
@param [String] string The string to wrap.
Calls superclass method
# File lib/claide/ansi/string_escaper.rb, line 9 def initialize(string) super end
Public Instance Methods
apply(*keys)
click to toggle source
@return [StringEscaper]
@param [Array<Symbol>] keys
One or more keys corresponding to ANSI codes to apply to the string.
# File lib/claide/ansi/string_escaper.rb, line 33 def apply(*keys) keys.flatten.each do |key| send(key) end self end
wrap_in_ansi_sequence(open, close)
click to toggle source
@return [StringEscaper] Wraps a string in the given ANSI
sequences,
taking care of handling existing sequences for the same family of attributes (i.e. attributes terminated by the same sequence).
# File lib/claide/ansi/string_escaper.rb, line 18 def wrap_in_ansi_sequence(open, close) if ANSI.disabled self else gsub!(close, open) insert(0, open).insert(-1, close) end end