Class: Morpheus::Logging::DarkPrinter
- Inherits:
-
Object
- Object
- Morpheus::Logging::DarkPrinter
- Includes:
- Term::ANSIColor
- Defined in:
- lib/morpheus/logging.rb
Overview
An IO class for printing debugging info This is used as a proxy for ::RestClient.log printing right now.
Instance Attribute Summary collapse
-
#color ⇒ Object
- String
-
ansi color code for output.
-
#io ⇒ Object
- IO
-
to write to.
Class Method Summary collapse
- .<<(*messages) ⇒ Object
-
.instance ⇒ Object
DarkPrinter with io STDOUT.
- .print(*messages) ⇒ Object
- .puts(*messages) ⇒ Object
Instance Method Summary collapse
- #<<(*messages) ⇒ Object
-
#initialize(io, color = nil, is_dark = true) ⇒ DarkPrinter
constructor
A new instance of DarkPrinter.
- #print(*messages) ⇒ Object
- #print_with_color(&block) ⇒ Object
- #puts(*messages) ⇒ Object
- #scrub_message(msg) ⇒ Object
Constructor Details
#initialize(io, color = nil, is_dark = true) ⇒ DarkPrinter
Returns a new instance of DarkPrinter.
122 123 124 125 126 |
# File 'lib/morpheus/logging.rb', line 122 def initialize(io, color=nil, is_dark=true) @io = io # || $stdout @color = color # || cyan @is_dark = is_dark end |
Instance Attribute Details
#color ⇒ Object
- String
-
ansi color code for output. Default is dark
103 104 105 |
# File 'lib/morpheus/logging.rb', line 103 def color @color end |
#io ⇒ Object
- IO
-
to write to
100 101 102 |
# File 'lib/morpheus/logging.rb', line 100 def io @io end |
Class Method Details
.<<(*messages) ⇒ Object
118 119 120 |
# File 'lib/morpheus/logging.rb', line 118 def self.<<(*) instance.<<(*) end |
.instance ⇒ Object
DarkPrinter with io STDOUT
106 107 108 |
# File 'lib/morpheus/logging.rb', line 106 def self.instance @instance ||= self.new(STDOUT, nil, true) end |
.print(*messages) ⇒ Object
110 111 112 |
# File 'lib/morpheus/logging.rb', line 110 def self.print(*) instance.print(*) end |
.puts(*messages) ⇒ Object
114 115 116 |
# File 'lib/morpheus/logging.rb', line 114 def self.puts(*) instance.puts(*) end |
Instance Method Details
#<<(*messages) ⇒ Object
166 167 168 |
# File 'lib/morpheus/logging.rb', line 166 def <<(*) print(*) end |
#print(*messages) ⇒ Object
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/morpheus/logging.rb', line 144 def print(*) if @io = .flatten.collect {|it| (it) } print_with_color do .each do |msg| @io.print msg end end end end |
#print_with_color(&block) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/morpheus/logging.rb', line 132 def print_with_color(&block) if Term::ANSIColor.coloring? @io.print Term::ANSIColor.reset @io.print @color if @color @io.print Term::ANSIColor.dark if @is_dark end yield if Term::ANSIColor.coloring? @io.print Term::ANSIColor.reset end end |
#puts(*messages) ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/morpheus/logging.rb', line 155 def puts(*) if @io = .flatten.collect {|it| (it) } print_with_color do .each do |msg| @io.puts msg end end end end |
#scrub_message(msg) ⇒ Object
128 129 130 |
# File 'lib/morpheus/logging.rb', line 128 def (msg) Morpheus::Logging.(msg) end |