lib/kafo/progress_bar.rb in kafo-6.1.2 vs lib/kafo/progress_bar.rb in kafo-6.2.0

- old
+ new

@@ -1,6 +1,7 @@ # encoding: UTF-8 +require 'highline' require 'powerbar' require 'ansi/code' require 'set' module Kafo @@ -18,11 +19,11 @@ def initialize @lines = 0 @all_lines = 0 @total = :unknown @resources = Set.new - @term_width = HighLine::SystemExtensions.terminal_size[0] || 0 + @term_width = terminal_width @bar = PowerBar.new @bar.settings.tty.infinite.template.main = infinite_template @bar.settings.tty.finite.template.main = finite_template @bar.settings.tty.finite.template.padchar = ' ' @bar.settings.tty.finite.template.barchar = '.' @@ -82,9 +83,20 @@ def print_error(line) print line end private + + def terminal_width + # HighLine 2 has Terminal, 1 has SystemExtensions + terminal_size = if HighLine.respond_to?(:default_instance) + HighLine.default_instance.terminal.terminal_size + else + HighLine::SystemExtensions.terminal_size + end + + terminal_size ? (terminal_size[0] || 0) : 0 + end def done_message text = 'Done' text + (' ' * (50 - text.length)) end