lib/bauxite/loggers/xterm.rb in bauxite-0.2.0 vs lib/bauxite/loggers/xterm.rb in bauxite-0.3.0

- old
+ new

@@ -66,14 +66,29 @@ def _restore_cursor print "\033[u" true end + #-- + # Adapted from: + # https://github.com/jimweirich/rake/blob/master/lib/rake/application.rb + # See Rake::Application#terminal_width + #++ def _screen_width - begin - require 'terminfo' - TermInfo.screen_size[1] - rescue Exception + if RbConfig::CONFIG['host_os'] =~ + /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i + (_dynamic_width_stty.nonzero? || _dynamic_width_tput) + else super end + rescue Exception => e + super end + +private + def _dynamic_width_stty + %x{stty size 2>/dev/null}.split[1].to_i + end + def _dynamic_width_tput + %x{tput cols 2>/dev/null}.to_i + end end \ No newline at end of file