Sha256: b584d25a4b9c5b787940cffc6ee10f62c7863bdbadaf3aa8adbdde0f2c71cc02

Contents?: true

Size: 858 Bytes

Versions: 1

Compression:

Stored size: 858 Bytes

Contents

require "winsize.so"
require "winsize/version"

module Winsize
  class Winsize
    attr_accessor :rows, :columns, :horizontal_pixels, :vertical_pixels

    def initialize(rows, columns, horizontal_pixels = 0, vertical_pixels = 0)
      @rows, @columns, @horizontal_pixels, @vertical_pixels = rows, columns, horizontal_pixels, vertical_pixels
    end

    def to_ioctl
      [rows, columns, horizontal_pixels, vertical_pixels].pack("SSSS")
    end
  end

  module IOExtensions
    # TIOCGWINSZ & TIOCSWINSZ are defined in ext/winsize.c

    def winsize
      size = ""
      ioctl(TIOCGWINSZ, size)
      Winsize.new(*size.unpack("SSSS"))
    end

    def winsize=(size)
      size = Winsize.new(*size) unless size.respond_to?(:to_ioctl)
      size = size.to_ioctl
      ioctl(TIOCSWINSZ, size)
    end
  end
end

class IO
  include Winsize::IOExtensions
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
winsize-1.0.0 lib/winsize.rb