Class: Bash_Visual::Font
- Inherits:
-
Object
- Object
- Bash_Visual::Font
- 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
-
#background ⇒ Object
readonly
Returns the value of attribute background.
-
#foreground ⇒ Object
readonly
Returns the value of attribute foreground.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Class Method Summary collapse
Instance Method Summary collapse
- #add_type(type) ⇒ Object
-
#initialize(types = :std, foreground = :white, background = nil) ⇒ Font
constructor
A new instance of Font.
- #inspect ⇒ Object
- #remove_type(type) ⇒ Object
- #to_s ⇒ Object (also: #to_bash)
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
#background ⇒ Object (readonly)
Returns the value of attribute background.
37 38 39 |
# File 'lib/bash-visual/font.rb', line 37 def background @background end |
#foreground ⇒ Object (readonly)
Returns the value of attribute foreground.
37 38 39 |
# File 'lib/bash-visual/font.rb', line 37 def foreground @foreground end |
#types ⇒ Object (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
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 |
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 |
#inspect ⇒ Object
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_s ⇒ Object Also known as: to_bash
69 70 71 |
# File 'lib/bash-visual/font.rb', line 69 def to_s @bash_command end |