Sha256: a36f46b2f75512750b21a337cbcef279d8cd5ce4b6f4575066f5b80faac52f8b

Contents?: true

Size: 627 Bytes

Versions: 7013

Compression:

Stored size: 627 Bytes

Contents

# frozen_string_literal: true

module Parser
  module Color
    def self.color(str, code, bold: false)
      return str unless STDOUT.tty?
      code = Array(code)
      code.unshift(1) if bold
      "\e[#{code.join(';')}m#{str}\e[0m"
    end

    def self.red(str, bold: false)
      color(str, 31, bold: bold)
    end

    def self.green(str, bold: false)
      color(str, 32, bold: bold)
    end

    def self.yellow(str, bold: false)
      color(str, 33, bold: bold)
    end

    def self.magenta(str, bold: false)
      color(str, 35, bold: bold)
    end

    def self.underline(str)
      color(str, 4)
    end
  end
end

Version data entries

7,013 entries across 6,990 versions & 51 rubygems

Version Path
cybrid_api_bank_ruby-0.123.135 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_id_ruby-0.123.135 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_bank_ruby-0.123.134 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_id_ruby-0.123.134 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_organization_ruby-0.123.134 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_bank_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_id_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_organization_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_bank_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_id_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_organization_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_bank_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_id_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_organization_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_bank_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_id_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_organization_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_bank_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_id_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb
cybrid_api_organization_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/parser-3.3.6.0/lib/parser/color.rb