Sha256: 4d146f5a1aacf90bed5bf134d55a6f4d35e10c1d15eed393665db0c630b7b77b

Contents?: true

Size: 408 Bytes

Versions: 13

Compression:

Stored size: 408 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]

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

      string
    end

  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rainbow-2.2.2/lib/rainbow/string_utils.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rainbow-2.2.2/lib/rainbow/string_utils.rb
pract6-0.1.0 .gem/ruby/2.3.0/gems/rainbow-2.2.2/lib/rainbow/string_utils.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rainbow-2.2.2/lib/rainbow/string_utils.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rainbow-2.2.2/lib/rainbow/string_utils.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rainbow-2.2.2/lib/rainbow/string_utils.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rainbow-2.2.2/lib/rainbow/string_utils.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rainbow-2.2.2/lib/rainbow/string_utils.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rainbow-2.2.2/lib/rainbow/string_utils.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rainbow-2.2.2/lib/rainbow/string_utils.rb
rainbow-2.2.2 lib/rainbow/string_utils.rb
rainbow-2.2.1 lib/rainbow/string_utils.rb
rainbow-2.1.0 lib/rainbow/string_utils.rb