lib/autobuild/progress_display.rb in autobuild-1.17.0 vs lib/autobuild/progress_display.rb in autobuild-1.18.0

- old
+ new

@@ -1,11 +1,10 @@ module Autobuild # Management of the progress display class ProgressDisplay def initialize(io, color: ::Autobuild.method(:color)) @io = io - #@cursor = Blank.new @cursor = TTY::Cursor @last_formatted_progress = [] @progress_messages = [] @silent = false @@ -19,11 +18,12 @@ def silent? @silent end def silent - @silent, silent = true, @silent + @silent = true + silent = @silent yield ensure @silent = silent end @@ -34,16 +34,15 @@ end def message(message, *args, io: @io, force: false) return if silent? && !force - if args.last.respond_to?(:to_io) - io = args.pop - end + io = args.pop if args.last.respond_to?(:to_io) @display_lock.synchronize do - io.print "#{@cursor.column(1)}#{@cursor.clear_screen_down}#{@color.call(message, *args)}\n" + io.print "#{@cursor.column(1)}#{@cursor.clear_screen_down}"\ + "#{@color.call(message, *args)}\n" io.flush if @io != io display_progress @io.flush end end @@ -92,13 +91,11 @@ def progress_done(key, display_last = true, message: nil) changed = @display_lock.synchronize do current_size = @progress_messages.size @progress_messages.delete_if do |msg_key, msg| if msg_key == key - if display_last && !message - message = msg - end + message = msg if display_last && !message true end end current_size != @progress_messages.size end @@ -114,15 +111,15 @@ end true end end - def display_progress return unless progress_enabled? - formatted = format_grouped_messages(@progress_messages.map(&:last), indent: " ") + formatted = format_grouped_messages(@progress_messages.map(&:last), + indent: " ") @io.print @cursor.clear_screen_down @io.print formatted.join("\n") if formatted.size > 1 @io.print "#{@cursor.up(formatted.size - 1)}#{@cursor.column(0)}" else @@ -135,38 +132,39 @@ msg = msg.split(" ") other_msg = other_msg.split(" ") msg.each_with_index do |token, idx| if other_msg[idx] != token prefix = msg[0..(idx - 1)].join(" ") - if !prefix.empty? - prefix << " " - end + prefix << " " unless prefix.empty? return prefix end end - return msg.join(" ") + msg.join(" ") end def group_messages(messages) messages = messages.sort groups = Array.new groups << ["", (0...messages.size)] messages.each_with_index do |msg, idx| - prefix, grouping = nil, false + prefix = nil + grouping = false messages[(idx + 1)..-1].each_with_index do |other_msg, other_idx| other_idx += idx + 1 prefix ||= find_common_prefix(msg, other_msg) - break if !other_msg.start_with?(prefix) + break unless other_msg.start_with?(prefix) if grouping break if prefix != groups.last[0] + groups.last[1] << other_idx else current_prefix, current_group = groups.last - if prefix.size > current_prefix.size # create a new group from there - groups.last[1] = (current_group.first..[idx-1,current_group.last].min) + if prefix.size > current_prefix.size # create a new group + group_end_index = [idx - 1, current_group.last].min + groups.last[1] = (current_group.first..group_end_index) groups << [prefix, [idx, other_idx]] grouping = true else break end end @@ -177,17 +175,18 @@ end groups.map do |prefix, indexes| indexes = indexes.to_a next if indexes.empty? + range = (prefix.size)..-1 [prefix, indexes.map { |i| messages[i][range] }] end.compact end - def format_grouped_messages(messages, indent: " ", width: TTY::Screen.width) - groups = group_messages(messages) + def format_grouped_messages(raw_messages, indent: " ", width: TTY::Screen.width) + groups = group_messages(raw_messages) groups.each_with_object([]) do |(prefix, messages), lines| if prefix.empty? lines.concat(messages.map { |m| "#{indent}#{m.strip}" }) next end @@ -195,13 +194,14 @@ lines << "#{indent}#{prefix.dup.strip} #{messages.shift}" until messages.empty? msg = messages.shift.strip margin = messages.empty? ? 1 : 2 if lines.last.size + margin + msg.size > width - lines << "".dup + lines.last << "," + lines << +"" lines.last << indent << indent << msg else - lines.last << " " << msg + lines.last << ", " << msg end end lines.last << "," unless messages.empty? end end