Sha256: 479ae6e03f426c721f8bc787545b0d8478d8ee2f5a008ff4925fad1d962d98c6

Contents?: true

Size: 999 Bytes

Versions: 1

Compression:

Stored size: 999 Bytes

Contents

module Vedeu

  # Change coordinates into an escape sequence to set the cursor position.
  #
  # @api private
  class Position

    # Initializes a new instance of Position.
    #
    # @param y [Fixnum]
    # @param x [Fixnum]
    # @return [Position]
    def initialize(y = 1, x = 1)
      @y, @x = y, x
    end

    # Returns an escape sequence to position the cursor. When passed a block,
    # will position the cursor, yield and return the original position.
    #
    # @param block [Proc]
    # @return [String]
    def to_s(&block)
      if block_given?
        [ sequence, yield, sequence ].join

      else
        sequence

      end
    end

    private

    # @api private
    # @return [String]
    def sequence
      ["\e[", y, ';', x, 'H'].join
    end

    # @api private
    # @return [Fixnum]
    def y
      (@y == 0 || @y == nil) ? 1 : @y
    end

    # @api private
    # @return [Fixnum]
    def x
      (@x == 0 || @x == nil) ? 1 : @x
    end

  end # Position

end # Vedeu

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.2.3 lib/vedeu/support/position.rb