commit b45609f64c869752bdbeddf4092cd313649c857e Author: Todd Lipcon Date: Sun May 30 12:09:36 2010 -0700 HBASE-2632. Shell should autodetect terminal width diff --git bin/hirb.rb bin/hirb.rb index 8bb5894..d6892b5 100644 --- bin/hirb.rb +++ bin/hirb.rb @@ -53,12 +53,10 @@ end cmdline_help = < format_width) +@formatter = Shell::Formatter::Console.new # Setup the HBase module. Create a configuration. @hbase = Hbase::Hbase.new diff --git src/main/ruby/shell/formatter.rb src/main/ruby/shell/formatter.rb index 1ddbc4a..e74dcee 100644 --- src/main/ruby/shell/formatter.rb +++ src/main/ruby/shell/formatter.rb @@ -29,15 +29,18 @@ module Shell obj.instance_of?(IO) || obj == Kernel end + def refresh_width() + @max_width = Java::jline.Terminal.getTerminal().getTerminalWidth() + end + # Takes an output stream and a print width. def initialize(opts = {}) options = { :output_stream => Kernel, - :format_width => 100 }.merge(opts) @out = options[:output_stream] - @max_width = options[:format_width] + refresh_width @row_count = 0 # raise an error if the stream is not valid @@ -45,6 +48,7 @@ module Shell end def header(args = [], widths = []) + refresh_width row(args, false, widths) if args.length > 0 @row_count = 0 end diff --git src/test/ruby/hbase/hbase_test.rb src/test/ruby/hbase/hbase_test.rb index 4403aac..4e3fae3 100644 --- src/test/ruby/hbase/hbase_test.rb +++ src/test/ruby/hbase/hbase_test.rb @@ -23,7 +23,7 @@ require 'hbase' module Hbase class HbaseTest < Test::Unit::TestCase def setup - @formatter = Shell::Formatter::Console.new(:format_width => 110) + @formatter = Shell::Formatter::Console.new() @hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration) end diff --git src/test/ruby/shell/shell_test.rb src/test/ruby/shell/shell_test.rb index 9469c2a..4289588 100644 --- src/test/ruby/shell/shell_test.rb +++ src/test/ruby/shell/shell_test.rb @@ -24,7 +24,7 @@ require 'shell/formatter' class ShellTest < Test::Unit::TestCase def setup - @formatter = ::Shell::Formatter::Console.new(:format_width => 110) + @formatter = ::Shell::Formatter::Console.new() @hbase = ::Hbase::Hbase.new @shell = Shell::Shell.new(@hbase, @formatter) end diff --git src/test/ruby/test_helper.rb src/test/ruby/test_helper.rb index e6c0e6a..1b542f5 100644 --- src/test/ruby/test_helper.rb +++ src/test/ruby/test_helper.rb @@ -23,7 +23,7 @@ end module Hbase module TestHelpers def setup_hbase - @formatter = Shell::Formatter::Console.new(:format_width => 110) + @formatter = Shell::Formatter::Console.new() @hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration) end