lib/termnote/pane.rb in termnote-1.1.0 vs lib/termnote/pane.rb in termnote-1.5.0

- old
+ new

@@ -1,9 +1,9 @@ +require_relative 'pane/helpers' require_relative 'pane/chapter' -require_relative 'pane/code' -require_relative 'pane/list' require_relative 'pane/text' +require_relative 'pane/code' require_relative 'pane/console' module TermNote module Pane attr_accessor :show, :height, :width, :rows @@ -25,17 +25,26 @@ def render puts show.header + space + formated_rows + space end def space - "\n" * (height / 2) + "\n" * (height / 2) end def formated_rows - rows.map { |row| gutter + row }.join("\n") + @output ||= rows.map(&method(:guttered_row)).join("\n") end - def gutter - " " * (width / 10) + 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