HBASE-2632. Shell should autodetect terminal width

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@949803 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Todd Lipcon 2010-05-31 16:49:50 +00:00
parent 57740b8e12
commit 12855081cc
6 changed files with 11 additions and 11 deletions

View File

@ -651,6 +651,7 @@ Release 0.21.0 - Unreleased
HBASE-2599 BaseScanner says "Current assignment of X is not valid" over
and over for same region
HBASE-2630 HFile should use toStringBinary in various places
HBASE-2632 Shell should autodetect terminal width
NEW FEATURES
HBASE-1961 HBase EC2 scripts

View File

@ -53,12 +53,10 @@ end
cmdline_help = <<HERE # HERE document output as shell usage
HBase Shell command-line options:
format Formatter for outputting results: console | html. Default: console
format-width Width of table outputs. Default: 110 characters.
-d | --debug Set DEBUG log levels.
HERE
found = []
format = 'console'
format_width = 110
script2run = nil
log_level = org.apache.log4j.Level::ERROR
for arg in ARGV
@ -72,9 +70,6 @@ for arg in ARGV
raise ArgumentError.new("Unsupported format " + arg)
end
found.push(arg)
elsif arg =~ /^--format-width=(.+)/i
format_width = $1.to_i
found.push(arg)
elsif arg == '-h' || arg == '--help'
puts cmdline_help
exit
@ -110,7 +105,7 @@ require 'shell/formatter'
# Presume console format.
# Formatter takes an :output_stream parameter, if you don't want STDOUT.
@formatter = Shell::Formatter::Console.new(:format_width => format_width)
@formatter = Shell::Formatter::Console.new
# Setup the HBase module. Create a configuration.
@hbase = Hbase::Hbase.new

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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