Class: Kojak::Printer::RandomlyColorized

Inherits:
Colorized show all
Defined in:
lib/kojak/printer/randomly_colorized.rb

Overview

Internal: Colorized logger that uses random color from the palette.

Constant Summary collapse

PALETTE =

Internal: List of colors to pick from. This list is always randomized on start.

%w[
  #af8700 #af875f #af8787 #af87af #af87d7 #af87ff #afaf00 #afaf5f
  #afafaf #afafd7 #afafff #afd700 #afd75f #afd787 #afd7af #afd7d7
  #afd7ff #afff00 #afff5f #afff87 #afffaf #afffd7 #afffff #878787
  #8787af #8787d7 #8787ff #87af00 #87af5f #87af87 #87afaf #87afd7
  #87afff #87d700 #87d75f #87d787 #87d7af #87d7d7 #87d7ff #87ff00
  #87ff5f #87ff87 #87ffaf #87ffd7 #87ffff #d78700 #d7875f #d78787
  #d787af #d787d7 #d787ff #d7af00 #d7af5f #d7af87 #d7afaf #d7afd7
].compact.shuffle

Instance Method Summary collapse

Methods inherited from Colorized

#write

Methods inherited from Synchronized

#write

Methods inherited from Basic

#write

Methods inherited from Kojak::Printer

#puts, #write

Constructor Details

#initialize(out) ⇒ RandomlyColorized

Returns a new instance of RandomlyColorized.



18
19
20
21
# File 'lib/kojak/printer/randomly_colorized.rb', line 18

def initialize(out)
  super(out, nil)
  @current = -1
end

Instance Method Details

#colorObject



23
24
25
26
27
28
# File 'lib/kojak/printer/randomly_colorized.rb', line 23

def color
  @@lock.synchronize do
    @current += 1
    PALETTE[@current % PALETTE.size]
  end
end