Skip to content

Instantly share code, notes, and snippets.

@acook
Created December 2, 2012 17:31
Show Gist options
  • Save acook/4190037 to your computer and use it in GitHub Desktop.
Save acook/4190037 to your computer and use it in GitHub Desktop.
Getting the terminal size in Ruby
# via http://www.megasolutions.net/ruby/Getting-the-size-of-the-terminal-in-a-portable-way-26006.aspx
TIOCGWINSZ = 0x40087468
def get_winsize
str = [0, 0, 0, 0].pack('SSSS')
if STDIN.ioctl(TIOCGWINSZ, str) >= 0
rows, cols, xpixels, ypixels = str.unpack("SSSS")
p rows, cols, xpixels, ypixels
else
puts "Unable to get window size"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment