Class: DevSystem::StickLog
- Inherits:
-
Log
- Object
- Liza::Unit
- Liza::Controller
- Log
- DevSystem::StickLog
- Defined in:
- lib/dev_system/sub/log/logs/stick_log.rb
Defined Under Namespace
Classes: Error, MissingText, UnknownArg
Constant Summary collapse
- FORE =
[255, 255, 255]
- STYLES =
{ bold: :b, italic: :i, underlined: :u, }
Instance Attribute Summary collapse
-
#back ⇒ Object
readonly
Returns the value of attribute back.
-
#bold ⇒ Object
readonly
Returns the value of attribute bold.
-
#fore ⇒ Object
readonly
Returns the value of attribute fore.
-
#italic ⇒ Object
readonly
Returns the value of attribute italic.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#underlined ⇒ Object
readonly
Returns the value of attribute underlined.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ StickLog
constructor
A new instance of StickLog.
- #to_s ⇒ Object
Methods inherited from Liza::Controller
color, inherited, on_connected
Methods inherited from Liza::Unit
const_missing, division, part, system, #system, test_class
Constructor Details
#initialize(*args) ⇒ StickLog
Returns a new instance of StickLog.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dev_system/sub/log/logs/stick_log.rb', line 29 def initialize *args bold = nil italic = nil underlined = nil fore = nil back = nil text = nil args.each do |arg| next text = arg if arg.is_a? String and text.nil? if arg.is_a? Symbol x = STYLES[arg] || arg next bold = true if x == :b next italic = true if x == :i next underlined = true if x == :u end next fore = arg unless fore next back = arg unless back raise UnknownArg, "unknown arg #{arg.inspect}" end raise MissingText, "missing a string as text", caller[3..] unless text fore ||= FORE fore = ColorShell.parse(fore) if fore and not fore.is_a? Array back = ColorShell.parse(back) if back and not back.is_a? Array # TODO: benchmark alternatives in regards to Object Shapes @bold = bold @italic = italic @underlined = underlined @fore = fore @back = back @text = text.to_s end |
Instance Attribute Details
#back ⇒ Object (readonly)
Returns the value of attribute back.
27 28 29 |
# File 'lib/dev_system/sub/log/logs/stick_log.rb', line 27 def back @back end |
#bold ⇒ Object (readonly)
Returns the value of attribute bold.
27 28 29 |
# File 'lib/dev_system/sub/log/logs/stick_log.rb', line 27 def bold @bold end |
#fore ⇒ Object (readonly)
Returns the value of attribute fore.
27 28 29 |
# File 'lib/dev_system/sub/log/logs/stick_log.rb', line 27 def fore @fore end |
#italic ⇒ Object (readonly)
Returns the value of attribute italic.
27 28 29 |
# File 'lib/dev_system/sub/log/logs/stick_log.rb', line 27 def italic @italic end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
27 28 29 |
# File 'lib/dev_system/sub/log/logs/stick_log.rb', line 27 def text @text end |
#underlined ⇒ Object (readonly)
Returns the value of attribute underlined.
27 28 29 |
# File 'lib/dev_system/sub/log/logs/stick_log.rb', line 27 def underlined @underlined end |
Class Method Details
.bundle(*args) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/dev_system/sub/log/logs/stick_log.rb', line 15 def self.bundle *args index = args.index { _1.is_a? Array and _1[0].is_a? String } or raise "missing array" common_args, arrays = args[0..index-1], args[index..-1] space = new(" ", *common_args).to_s arrays.map { |array| new *[*common_args, *array] }.join space end |
Instance Method Details
#to_s ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dev_system/sub/log/logs/stick_log.rb', line 67 def to_s s = "" s += "\e[1m" if @bold s += "\e[3m" if @italic s += "\e[4m" if @underlined s += "\e[38;2;#{@fore[0]};#{@fore[1]};#{@fore[2]}m" if @fore s += "\e[48;2;#{@back[0]};#{@back[1]};#{@back[2]}m" if @back s += @text s += "\e[0m" s end |