Sha256: dc1f1af0d87f958c362986255cc14f2d96bcebe659185c5f4080096024d3b870

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

module TP
  class Presenter
    attr_accessor :markdown

    def initialize(markdown)
      self.markdown = markdown
    end

    def present
      Screen.suggest 30, 8
      Keyboard.wait_for_return

      loop do
        Screen.clear!

        show_slide slide_deck.current or break

        case Keyboard.read
        when :right, :down, :space, :return, 'l', 'k'
          slide_deck.next
        when :left, :up, :backspace, 'h', 'j'
          slide_deck.previous
        when 'q'
          break
        end
      end

      Screen.clear!
    end

    def slides
      result = markdown.split /^# /
      result.reject! &:empty?
      result.map! { |string| string.prepend "#" }

      result.map { |string| Slide.new string }
    end

    def slide_deck
      @slide_deck ||= SlideDeck.new slides
    end

    def show_slide(slide)
      return unless slide

      buffer = slide.header.center Screen.width

      if slide.body
        buffer << "\n\n"

        if slide.paragraph
          buffer << slide.paragraph.center(Screen.width)
        else
          slide.bullets.each { |string| buffer << "#{bullet}#{string}\n" }
        end
      end

      print buffer

      true
    end

    def bullet
      "\u2022 "
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tp-0.1.0 lib/tp/presenter.rb