Sha256: cead309b8b49f3b3d46679ca764b5d7a1d6c7fd4e0cf687e7a2e919c468bd303

Contents?: true

Size: 949 Bytes

Versions: 1

Compression:

Stored size: 949 Bytes

Contents

module JarEd
  class Pane
    def refresh(window)
      screen = view.to_screen
      validate!(screen)
      window.clear
      draw_screen(window, screen)
      window.setpos(screen.cursor_row, screen.cursor_column)
      window.noutrefresh
    end

    def send_input(char)
      view.send_input(char)
    end

    def view=(view)
      view.pane = self
      @view = view
    end

    def width
      Curses.cols
    end

    def height
      Curses.lines
    end

    private

    attr_reader :view

    def draw_screen(window, screen)
      screen.lines.each_with_index do |line, index|
        window.setpos index, 0
        window.addstr line
      end
    end

    # @todo Validate that the screen fits in the pane.
    def validate!(screen)
      screen.cursor_column >= 0 &&
        screen.cursor_row >= 0 &&
        screen.cursor_column < width &&
        screen.cursor_row < height ||
        raise("Invalid screen.")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jareditor-3.0.0 lib/jared/pane.rb