Sha256: 965133de9088e9e3cb754bbe5fcb62292c3fc4e8f37fa461762b9dcff069164b

Contents?: true

Size: 976 Bytes

Versions: 2

Compression:

Stored size: 976 Bytes

Contents

require_relative 'pane/helpers'
require_relative 'pane/chapter'
require_relative 'pane/text'
require_relative 'pane/code'
require_relative '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-1.5.1 lib/termnote/pane.rb
termnote-1.5.0 lib/termnote/pane.rb