lib/autobuild/progress_display.rb in autobuild-1.14.1 vs lib/autobuild/progress_display.rb in autobuild-1.15.0

- old
+ new

@@ -31,19 +31,19 @@ def progress_enabled? !@silent && @progress_enabled end - def message(message, *args, io: @io) - return if silent? + def message(message, *args, io: @io, force: false) + return if silent? && !force if args.last.respond_to?(:to_io) io = args.pop end @display_lock.synchronize do - io.print "#{@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 @@ -117,11 +117,11 @@ end def display_progress return unless progress_enabled? - + 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)}" @@ -182,28 +182,29 @@ range = (prefix.size)..-1 [prefix, indexes.map { |i| messages[i][range] }] end.compact end - def format_grouped_messages(messages, indent: " ") - terminal_w = TTY::Screen.width + def format_grouped_messages(messages, indent: " ", width: TTY::Screen.width) groups = group_messages(messages) groups.each_with_object([]) do |(prefix, messages), lines| if prefix.empty? - lines << "#{indent}#{messages.shift}" - else - lines << "#{indent}#{prefix.dup.strip} #{messages.shift}" + lines.concat(messages.map { |m| "#{indent}#{m.strip}" }) + next end + + lines << "#{indent}#{prefix.dup.strip} #{messages.shift}" until messages.empty? msg = messages.shift.strip - if lines.last.size + 2 + msg.size > terminal_w - lines << "#{indent} #{msg}" + margin = messages.empty? ? 1 : 2 + if lines.last.size + margin + msg.size > width + lines << "".dup + lines.last << indent << indent << msg else - lines.last << ", #{msg}" + lines.last << " " << msg end end - lines + lines.last << "," unless messages.empty? end end end end -