Sha256: a5b011f0f13abbd8d8bc0d2f71a126b10395f4c9fa14e7330e5dd719cdbf49fb

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

# coding: utf-8

require 'tty/screen/size'
require 'tty/screen/version'

module TTY
  # Used for detecting screen properties
  #
  # @api public
  class Screen
    # Create terminal screen
    #
    # @param [Hash] options
    # @option options [Object] :output
    #   the object that responds to print call defaulting to stderr
    #
    # @api public
    def initialize(options = {})
      @output  = options.fetch(:output) { $stderr }
      @verbose = options.fetch(:verbose) { false }
      @size    = Size.new(ENV, output: @output, verbose: @verbose)
    end

    # @api public
    def self.size
      new.size
    end

    # @api public
    def self.width
      size[1]
    end

    # @api public
    def self.height
      size[0]
    end

    # Terminal size as tuple
    #
    # @return [Array[Integer]]
    #
    # @api public
    def size
      @size.size
    end

    # Terminal lines count
    #
    # @return [Integer]
    #
    # @api public
    def height
      size[0]
    end
    alias_method :rows, :height

    # Terminal columns count
    #
    # @return [Integer]
    #
    # @api public
    def width
      size[1]
    end
    alias_method :columns, :width
  end # Screen
end # TTY

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tty-screen-0.5.0 lib/tty/screen.rb