Class: Notifaction::Style
- Inherits:
-
Object
- Object
- Notifaction::Style
- Defined in:
- lib/notifaction/style.rb
Instance Method Summary collapse
-
#format(message, colour = nil, style = nil) ⇒ Object
Return an ASCII-formatted string for display in common command line terminals.
-
#initialize ⇒ Style
constructor
Create the map hash.
Constructor Details
#initialize ⇒ Style
Create the map hash
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/notifaction/style.rb', line 5 def initialize @map = { colour: { red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37, null: 0 }, style: { reset: 0, bold: 1, underline: 4, normal: "" } } end |
Instance Method Details
#format(message, colour = nil, style = nil) ⇒ Object
Return an ASCII-formatted string for display in common command line terminals
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/notifaction/style.rb', line 29 def format(, colour = nil, style = nil) c = @map[:colour][colour.to_sym] unless colour.nil? if style.nil? t = 0 else t = @map[:style][style.to_sym] end "\e[#{t};#{c}m#{message}\e[0m" end |