Sha256: 00193c4a3520ceff1b9a8f936103be8270696afc63a8137d3dae4e823c9099e0

Contents?: true

Size: 968 Bytes

Versions: 1

Compression:

Stored size: 968 Bytes

Contents

require 'termnote/show/key'

module TermNote
  class Show
    attr_accessor :panes, :state
    attr_writer :pane

    def initialize
      @panes ||= []
    end

    def add(pane)
      raise ArgumentError, "Pane required" if pane.nil?
      panes << pane
      pane.show = self
    end

    def pane
      @pane || panes.first
    end

    def position
      panes.index pane
    end

    def total
      panes.size
    end

    def start
      @state = true
      while @state
        pane.call $stdout.winsize
        Key.send @command, self if Key::KEYS.include? capture_command
      end
    end

    def close
      @state = false
    end

    def header
      "[#{position + 1}/#{total}] - #{panes.first.title}\n".bold
    end

    def forward
      @pane = panes[position + 1] || panes.first
    end

    def backward
      @pane = panes[position - 1] || panes.last
    end

    private

    def capture_command
      @command = $stdin.getch
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
termnote-2.0.1 lib/termnote/show.rb