Module: TerminalInfo

Defined in:
lib/sitefuel/extensions/TerminalInfo.rb

Overview

File

TerminalInfo.rb

Author

wkm

Copyright

2009, Zanoccio LLC.

License

GPL version 2.0 (see LICENSE.rb)

Little Ruby library for querying for various properties of a terminal window.

Class Method Summary collapse

Class Method Details

.dimensionsObject

gives an array containing the current dimensions of the terminal window

Note that unlike =stty= (and #size) the first parameter is the width of the window (x) and the second parameter is the height of the window (y)

TerminalInfo.dimensions # => [105, 34]


20
21
22
23
24
# File 'lib/sitefuel/extensions/TerminalInfo.rb', line 20

def self.dimensions
  grab_output('stty size').split(' ').reverse.map do |val|
    val.to_i
  end
end

.heightObject

gives the current height of the terminal window



42
43
44
# File 'lib/sitefuel/extensions/TerminalInfo.rb', line 42

def self.height
  dimensions.last
end

.sizeObject

gives an array with the current size of the terminal window

Note that the first parameter is the height of the window, just like with

stty=

TerminalInfo.size # => [34, 105]


32
33
34
# File 'lib/sitefuel/extensions/TerminalInfo.rb', line 32

def self.size
  dimensions.reverse
end

.widthObject

gives the current width of the terminal window



37
38
39
# File 'lib/sitefuel/extensions/TerminalInfo.rb', line 37

def self.width
  dimensions.first
end