Sha256: 41c27a3ee860ea2fde968f0b07b6d06dd43f6f1f53c75f58aad682f29d7cac17

Contents?: true

Size: 653 Bytes

Versions: 2

Compression:

Stored size: 653 Bytes

Contents

require 'rainbow'

module Repper
  class Theme
    def self.cast(arg)
      case arg
      when Theme              then arg
      when ::Hash             then Theme.new(**arg)
      when ::Symbol, ::String then Theme.const_get(arg.capitalize) rescue nil
      when false, nil         then Theme::Plain
      end || raise(Repper::ArgumentError, "unknown theme #{arg.inspect}")
    end

    def initialize(**colors)
      @colors = colors
    end

    def colorize(str, type)
      color = @colors[type] || @colors[:default]
      color ? Rainbow(str).color(color).bold : str
    end
  end
end

::Dir["#{__dir__}/theme/*.rb"].each { |file| require file }

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
repper-1.1.0 lib/repper/theme.rb
repper-1.0.0 lib/repper/theme.rb