Class: Rainbow::StringUtils

### Home Classes Methods

### In Files

- lib/rainbow/string_utils.rb

### Parent

Object

### Methods

- ::wrap_with_sgr

### Class/Module Index

Quicksearch

- Rainbow
- Rainbow::Color
- Rainbow::Color::Indexed
- Rainbow::Color::Named
- Rainbow::Color::RGB
- Rainbow::Ext
- Rainbow::Ext::String
- Rainbow::Ext::String::InstanceMethods
- Rainbow::NullPresenter
- Rainbow::Presenter
- Rainbow::StringUtils
- Rainbow::Wrapper
- Sickill
- Sickill::Rainbow
- Object

No matching classes.

# Rainbow::StringUtils

### Public Class Methods

wrap_with_sgr(string, codes) click to toggle source

    # File lib/rainbow/string_utils.rb, line 4
    def self.wrap_with_sgr(string, codes)
      return string if codes.empty?

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

      if match
        seq_pos = match.end(0)
        string = string[0...seq_pos] + seq + string[seq_pos..-1]
      else
        string = seq + string
      end

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

      string
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.