Sha256: 718c50767ddb11af56f54e535a3b028fe3dda97c894693b6b867e3f54feb2882

Contents?: true

Size: 892 Bytes

Versions: 1

Compression:

Stored size: 892 Bytes

Contents

module TP
  class Presenter
    attr_accessor :markdown

    def initialize(markdown)
      self.markdown = markdown
    end

    def present
      Screen.suggest slide_deck.width, slide_deck.height
      Keyboard.wait_for_return

      loop do
        Renderer.new(slide_deck.current_frame).render

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

        break if slide_deck.ended?
      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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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