def terminal_width(default_width = 81, out = STDOUT)
      tiocgwinsz = 0x5413
      data = [0, 0, 0, 0].pack('SSSS')
      if !RUBY_PLATFORM.include?('java') && out.ioctl(tiocgwinsz, data) >= 0 # JRuby crashes on ioctl
        _, cols, _, _ = data.unpack('SSSS')
        fail unless cols > 0
        cols
      else
        fail
      end
    rescue
      begin
        IO.popen('stty -a 2>&1') do |pipe|
          column_line = pipe.find { |line| /(\d+) columns/ =~ line }
          fail unless column_line
          Regexp.last_match[1].to_i
        end
      rescue
        default_width
      end
    end
def terminal_width(default_width = 81, out = STDOUT)
      tiocgwinsz = 0x5413
      data = [0, 0, 0, 0].pack('SSSS')
      if !RUBY_PLATFORM.include?('java') && out.ioctl(tiocgwinsz, data) >= 0 # JRuby crashes on ioctl
        _, cols, _, _ = data.unpack('SSSS')
        fail unless cols > 0
        cols
      else
        fail
      end
    rescue
      begin
        IO.popen('stty -a 2>&1') do |pipe|
          column_line = pipe.find { |line| /(\d+) columns/ =~ line }
          fail unless column_line
          Regexp.last_match[1].to_i
        end
      rescue
        default_width
      end
    end
Try to determine the terminal with.
 If it is not possible to to so, it returns the default_width.
 <tt>default_width</tt> Defaults to 81