Class: Plywood::FancyLogger::Frame
- Inherits:
-
Object
- Object
- Plywood::FancyLogger::Frame
- Defined in:
- lib/plywood/fancy_logger/frame.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(io, rows = nil, cols = nil) ⇒ Frame
constructor
A new instance of Frame.
- #line(string, color = nil) ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(io, rows = nil, cols = nil) ⇒ Frame
Returns a new instance of Frame.
6 7 8 9 10 11 12 |
# File 'lib/plywood/fancy_logger/frame.rb', line 6 def initialize(io, rows = nil, cols = nil) rows, cols = IO.console.winsize if rows.nil? || cols.nil? @io = io @rows = rows.to_i - 1 @cols = cols.to_i @lines = [] end |
Class Method Details
.render {|frame| ... } ⇒ Object
14 15 16 17 18 |
# File 'lib/plywood/fancy_logger/frame.rb', line 14 def self.render(*, &) frame = new(*) yield frame frame.render end |
Instance Method Details
#line(string, color = nil) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/plywood/fancy_logger/frame.rb', line 20 def line(string, color = nil) return if @lines.size >= @rows string = string.to_s[0, @cols].ljust(@cols) string = @io.color(color) + string + @io.color(:reset) if color @lines << string self end |
#render ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/plywood/fancy_logger/frame.rb', line 28 def render @lines << "".ljust(@cols) until @lines.size == @rows @lines.each.with_index do |line, index| # position_cursor(@rows - @lines.size + index + 1, 1) position_cursor(index + 1, 1) @io << line end end |