[Groonga-commit] groonga/grntest [master] Guess terminal width from 'stty -a'

Back to archive index

Kouhei Sutou null+****@clear*****
Sat Aug 11 20:25:00 JST 2012


Kouhei Sutou	2012-08-11 20:25:00 +0900 (Sat, 11 Aug 2012)

  New Revision: a99c0ed8e887834c697af7f23c89cbf012e183ec
  https://github.com/groonga/grntest/commit/a99c0ed8e887834c697af7f23c89cbf012e183ec

  Log:
    Guess terminal width from 'stty -a'

  Modified files:
    lib/groonga/tester.rb

  Modified: lib/groonga/tester.rb (+18 -1)
===================================================================
--- lib/groonga/tester.rb    2012-08-11 20:24:47 +0900 (e6fe340)
+++ lib/groonga/tester.rb    2012-08-11 20:25:00 +0900 (85b0ca6)
@@ -1520,11 +1520,28 @@ EOF
       end
 
       def guess_term_width
-        Integer(ENV["COLUMNS"] || ENV["TERM_WIDTH"] || 79)
+        Integer(guess_term_width_from_env || guess_term_width_from_stty || 79)
       rescue ArgumentError
         0
       end
 
+      def guess_term_width_from_env
+        ENV["COLUMNS"] || ENV["TERM_WIDTH"]
+      end
+
+      def guess_term_width_from_stty
+        case `stty -a`
+        when /(\d+) columns/
+          $1
+        when /columns (\d+)/
+          $1
+        else
+          nil
+        end
+      rescue SystemCallError
+        nil
+      end
+
       def string_width(string)
         string.gsub(/\e\[[0-9;]+m/, "").size
       end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index