lib/tailstrom/command/stat.rb in tailstrom-0.0.5 vs lib/tailstrom/command/stat.rb in tailstrom-0.0.6

- old
+ new

@@ -27,11 +27,11 @@ reader = TailReader.new @infile, @options reader.each_line do |line| @counters[line[:key]] << line[:value] end - height = `put lines`.to_i - 4 rescue 10 + height = terminal_height i = 0 begin sleep @options[:interval] if i % height == 0 @@ -50,10 +50,19 @@ rescue Interrupt exit 0 end private + def terminal_height + system 'which tput 2>&1 >/dev/null' + if $? == 0 + `tput lines`.to_i - 4 + else + 10 + end + end + def print_counters sorted_counters.each do |key, c| key = (key == :nil ? nil : key) next unless out_filter(key, c) if @options[:async] @@ -66,16 +75,16 @@ end def sorted_counters counters = @counters.to_a if sort = @options[:sort] - counters.sort_by! do |key, c| + counters = counters.sort_by do |key, c| sum, avg, min, max, count = c.sum, c.avg, c.min, c.max, c.count binding.eval sort end else - counters.sort_by! do |key, c| + counters = counters.sort_by do |key, c| c.sum end end @options[:order] == :asc ? counters : counters.reverse end