Sha256: c07efab25960231d4054dac739323569541a928224df8304e13b01a348eff71c

Contents?: true

Size: 563 Bytes

Versions: 97

Compression:

Stored size: 563 Bytes

Contents

module Rainbow
  class StringUtils
    def self.wrap_with_sgr(string, codes)
      return string if codes.empty?

      seq = "\e[" + codes.join(";") + "m"
      match = string.match(/^(\e\[([\d;]+)m)*/)
      seq_pos = match.end(0)
      string = string[0...seq_pos] + seq + string[seq_pos..-1]

      string += "\e[0m" unless string =~ /\e\[0m$/

      string
    end

    def self.uncolor(string)
      # See http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed
      string.gsub(/\e\[[0-9;]*m/, '')
    end
  end
end

Version data entries

97 entries across 90 versions & 19 rubygems

Version Path
primary_connect_proto-0.20.0 vendor/bundle/ruby/2.6.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.20.0 vendor/bundle/ruby/3.0.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.19.0 vendor/bundle/ruby/3.0.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.18.0 vendor/bundle/ruby/2.6.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.18.0 vendor/bundle/ruby/3.0.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.17.0 vendor/bundle/ruby/2.6.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.17.0 vendor/bundle/ruby/3.0.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.12.1 vendor/bundle/ruby/2.7.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.10.2 vendor/bundle/ruby/2.7.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.10.1 vendor/bundle/ruby/2.7.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.9.0 vendor/bundle/ruby/2.6.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.8.2 vendor/bundle/ruby/2.7.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.8.1 vendor/bundle/ruby/2.7.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.8.0 vendor/bundle/ruby/2.6.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.7.3 vendor/bundle/ruby/2.6.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.7.2 vendor/bundle/ruby/2.6.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.7.1 vendor/bundle/ruby/2.6.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.7.0 vendor/bundle/ruby/2.6.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
primary_connect_proto-0.6.0 vendor/bundle/ruby/2.6.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rainbow-3.0.0/lib/rainbow/string_utils.rb