Class: DevSystem::StickLog

Inherits:
Log show all
Defined in:
lib/dev_system/subsystems/log/logs/stick_log.rb

Defined Under Namespace

Classes: Error, MissingText, UnknownArg

Constant Summary collapse

FORE =
:black
STYLES =
{
  bold: :b,
  italic: :i,
  underlined: :u,
}

Instance Attribute Summary collapse

Attributes inherited from Liza::Controller

#menv

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Liza::Controller

#`, `, attr_accessor, attr_reader, attr_writer, #attrs, box, #box, call, color, division, division!, division?, inherited, menv_accessor, menv_reader, menv_writer, on_connected, panel, #panel, plural, require, requirements, sh, #sh, singular, subsystem, subsystem!, subsystem?, subsystem_token, token

Methods inherited from Liza::Unit

_erbs_for, #add, add, cl, #cl, class_methods_defined, const_added, const_missing, constants_defined, define_error, descendants_select, division, erbs_available, erbs_defined, erbs_for, errors, #fetch, fetch, get, #get, instance_methods_defined, log, #log, log?, #log?, #log_array, log_array, log_hash, #log_hash, #log_level, log_level, #log_level?, log_level?, log_levels, #log_levels, #log_render_convert, #log_render_format, #log_render_in, #log_render_out, method_added, methods_defined, namespace, part, raise_error, #raise_error, reload!, #reload!, #render, #render!, #render_stack, renderable_formats_for, renderable_names, section, sections, #set, set, #settings, settings, singleton_method_added, sleep, #sleep, stick, #stick, sticks, #sticks, subclasses_select, subunits, system, #system, system?, test_class, time_diff, #time_diff

Constructor Details

#initialize(*args) ⇒ StickLog

Returns a new instance of StickLog.

Raises:



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
66
# File 'lib/dev_system/subsystems/log/logs/stick_log.rb', line 30

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 = PalletShell.find(fore) if fore and not fore.is_a? ColorShell
  back = PalletShell.find(back) if back and not back.is_a? ColorShell

  # TODO: benchmark alternatives in regards to Object Shapes
  @bold = bold
  @italic = italic
  @underlined = underlined
  @fore = fore&.to_rgb
  @back = back&.to_rgb
  @text = text.to_s
end

Instance Attribute Details

#backObject (readonly)

Returns the value of attribute back.



28
29
30
# File 'lib/dev_system/subsystems/log/logs/stick_log.rb', line 28

def back
  @back
end

#boldObject (readonly)

Returns the value of attribute bold.



28
29
30
# File 'lib/dev_system/subsystems/log/logs/stick_log.rb', line 28

def bold
  @bold
end

#foreObject (readonly)

Returns the value of attribute fore.



28
29
30
# File 'lib/dev_system/subsystems/log/logs/stick_log.rb', line 28

def fore
  @fore
end

#italicObject (readonly)

Returns the value of attribute italic.



28
29
30
# File 'lib/dev_system/subsystems/log/logs/stick_log.rb', line 28

def italic
  @italic
end

#textObject (readonly)

Returns the value of attribute text.



28
29
30
# File 'lib/dev_system/subsystems/log/logs/stick_log.rb', line 28

def text
  @text
end

#underlinedObject (readonly)

Returns the value of attribute underlined.



28
29
30
# File 'lib/dev_system/subsystems/log/logs/stick_log.rb', line 28

def underlined
  @underlined
end

Class Method Details

.bundle(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/dev_system/subsystems/log/logs/stick_log.rb', line 16

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_sObject



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dev_system/subsystems/log/logs/stick_log.rb', line 68

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