Class: Plywood::FancyLogger::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/plywood/fancy_logger/frame.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Yields:

  • (frame)


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

#renderObject



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