Sha256: 5a77870b0d263487f204c7f286fc21285eaf6cec9584245035266cb5bcb180ed

Contents?: true

Size: 976 Bytes

Versions: 2

Compression:

Stored size: 976 Bytes

Contents

require 'termnote/pane/helpers'
require 'termnote/pane/chapter'
require 'termnote/pane/text'
require 'termnote/pane/code'
require 'termnote/pane/console'

module TermNote
  module Pane
    attr_accessor :show, :height, :width, :rows

    def call(window_size)
      window_height, window_width = window_size
      @width = window_width
      @height = window_height
      clear
      render
    end

    private

    def clear
      system("clear")
    end

    def render
      puts show.header + space + formated_rows + space
    end

    def space
     "\n" * (height / 2)
    end

    def formated_rows
      @output ||= rows.map(&method(:guttered_row)).join("\n")
    end

    def guttered_row(row)
      raise ArgumentError, "content was larger than screen" if gutter_width(row) < 0
      gutter(row) + row
    end

    def gutter(row)
      " " * gutter_width(row)
    end

    def gutter_width(row)
      (width / 2.0).floor - (row.width / 2.0).ceil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
termnote-2.0.1 lib/termnote/pane.rb
termnote-2.0.0 lib/termnote/pane.rb