lib/cli/tools.rb in request-log-analyzer-1.5.1 vs lib/cli/tools.rb in request-log-analyzer-1.5.2
- old
+ new
@@ -1,26 +1,29 @@
# 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
def terminal_width(default_width = 81)
- tiocgwinsz = 0x5413
- data = [0, 0, 0, 0].pack("SSSS")
- if @out.ioctl(tiocgwinsz, data) >= 0
- rows, cols, xpixels, ypixels = data.unpack("SSSS")
- raise unless cols > 0
- cols
- else
- raise
- end
-rescue
+
begin
- IO.popen('stty -a 2>&1') do |pipe|
- column_line = pipe.detect { |line| /(\d+) columns/ =~ line }
- raise unless column_line
- $1.to_i
+ tiocgwinsz = 0x5413
+ data = [0, 0, 0, 0].pack("SSSS")
+ if !RUBY_PLATFORM.include?('java') && @out.ioctl(tiocgwinsz, data) >= 0 # JRuby crashes on ioctl
+ rows, cols, xpixels, ypixels = data.unpack("SSSS")
+ raise unless cols > 0
+ cols
+ else
+ raise
end
- rescue
- default_width
+ rescue
+ begin
+ IO.popen('stty -a 2>&1') do |pipe|
+ column_line = pipe.detect { |line| /(\d+) columns/ =~ line }
+ raise unless column_line
+ $1.to_i
+ end
+ rescue
+ default_width
+ end
end
end
# Copies request-log-analyzer analyzer rake tasks into the /lib/tasks folder of a project, for easy access and
# environment integration.