Class: Bash_Visual::Font

Inherits:
Object
  • Object
show all
Defined in:
lib/bash-visual/font.rb

Constant Summary collapse

COLORS =
[:black, :dark_red, :dark_green, :dark_yellow, :dark_blue, :dark_magenta, :dark_cyan, :grey,
:dark_grey, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
TYPES =
[:std, :bold, :underline, :blink]
RESET =
"\e[0m"
@@colors_map =
{
    black:        0,
    dark_red:     1,
    dark_green:   2,
    dark_yellow:  3,
    dark_blue:    4,
    dark_magenta: 5,
    dark_cyan:    6,
    grey:         7,
    dark_grey:    10,
    red:          11,
    green:        12,
    yellow:       13,
    blue:         14,
    magenta:      15,
    cyan:         16,
    white:        17
}
@@types_map =
{
    std:       0,
    bold:      1,
    underline: 4,
    blink:     5
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types = :std, foreground = :white, background = nil) ⇒ Font

Returns a new instance of Font.



39
40
41
42
# File 'lib/bash-visual/font.rb', line 39

def initialize(types = :std, foreground = :white, background = nil)

  build(types, foreground, background)
end

Instance Attribute Details

#backgroundObject (readonly)

Returns the value of attribute background.



37
38
39
# File 'lib/bash-visual/font.rb', line 37

def background
  @background
end

#foregroundObject (readonly)

Returns the value of attribute foreground.



37
38
39
# File 'lib/bash-visual/font.rb', line 37

def foreground
  @foreground
end

#typesObject (readonly)

Returns the value of attribute types.



37
38
39
# File 'lib/bash-visual/font.rb', line 37

def types
  @types
end

Class Method Details

.rand_color(exclude_color = nil) ⇒ Object

Parameters:

  • exclude_color (Symbol) (defaults to: nil)


78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/bash-visual/font.rb', line 78

def rand_color (exclude_color = nil)
  color = rand(16)
  color += 2 if color > 7

  if color == @@colors_map[exclude_color]
    color += 1
    color = 0 if color > 17
  end

  @@colors_map.each do |name, code|
    return name if code == color
  end

end

.rand_fontObject



93
94
95
96
# File 'lib/bash-visual/font.rb', line 93

def rand_font
   color = self.rand_color
   Font.new :std, color
end

Instance Method Details

#add_type(type) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/bash-visual/font.rb', line 44

def add_type(type)
  return false if @types.include? type

  @types << type
  build(@types, @foreground, @background)

  true
end

#inspectObject



64
65
66
67
# File 'lib/bash-visual/font.rb', line 64

def inspect
  "<Font types=%s, foreground=%s, background=%s>" %
      [@types, @foreground, (@background ? @background : 'nil')]
end

#remove_type(type) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/bash-visual/font.rb', line 53

def remove_type(type)

  return false unless @types.include? type
  return false if @types == [:std]

  @types.delete type
  build(@types, @foreground, @background)

  true
end

#to_sObject Also known as: to_bash



69
70
71
# File 'lib/bash-visual/font.rb', line 69

def to_s
  @bash_command
end