Class: Repper::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/repper/theme.rb,
lib/repper/theme/plain.rb,
lib/repper/theme/default.rb,
lib/repper/theme/monokai.rb

Constant Summary collapse

Plain =
new
Default =
new(
  anchor:        :yellow,
  annotation:    nil, # only for annotated formats
  assertion:     :green,
  backref:       :blue,
  conditional:   :green,
  escape:        :red,
  expression:    :red, # root
  free_space:    nil,
  group:         :blue,
  keep:          :yellow,
  literal:       :red,
  meta:          :magenta,
  nonposixclass: :cyan,
  nonproperty:   :cyan,
  posixclass:    :cyan,
  property:      :cyan,
  quantifier:    :white,
  set:           :cyan,
  type:          :cyan,
)
Monokai =
new(
  anchor:        '#FD971F',
  annotation:    '#75715E', # only for annotated formats
  assertion:     '#A6E22E',
  backref:       '#66D9EF',
  conditional:   '#A6E22E',
  escape:        '#F92672',
  expression:    '#F92672', # root
  free_space:    '#75715E',
  group:         '#66D9EF',
  keep:          '#FD971F',
  literal:       '#F92672',
  meta:          '#E69F66',
  nonposixclass: '#AE81FF',
  nonproperty:   '#AE81FF',
  posixclass:    '#AE81FF',
  property:      '#AE81FF',
  quantifier:    '#F8F8F2',
  set:           '#AE81FF',
  type:          '#AE81FF',
)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**colors) ⇒ Theme

Returns a new instance of Theme.



14
15
16
# File 'lib/repper/theme.rb', line 14

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

Class Method Details

.cast(arg) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/repper/theme.rb', line 5

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

Instance Method Details

#colorize(str, type) ⇒ Object



18
19
20
21
# File 'lib/repper/theme.rb', line 18

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