lib/yard/logging.rb in yard-0.9.8 vs lib/yard/logging.rb in yard-0.9.9
- old
+ new
@@ -1,17 +1,18 @@
# frozen_string_literal: true
+# encoding: utf-8
require 'logger'
require 'thread'
module YARD
# Handles console logging for info, warnings and errors.
# Uses the stdlib Logger class in Ruby for all the backend logic.
class Logger < ::Logger
# The list of characters displayed beside the progress bar to indicate
# "movement".
# @since 0.8.2
- PROGRESS_INDICATORS = ["\u230C", "\u230D", "\u230E", "\u230F"]
+ PROGRESS_INDICATORS = %w(⣷ ⣯ ⣟ ⡿ ⢿ ⣻ ⣽ ⣾)
# @return [IO] the IO object being logged to
# @since 0.8.2
def io; @logdev end
def io=(pipe) @logdev = pipe end
@@ -47,10 +48,11 @@
self.level = WARN
self.formatter = method(:format_log)
@progress_indicator = 0
@mutex = Mutex.new
@progress_msg = nil
+ @progress_last_update = Time.now
end
# Changes the debug level to DEBUG if $DEBUG is set
# and writes a debugging message.
def debug(*args)
@@ -91,11 +93,14 @@
icon = PROGRESS_INDICATORS[@progress_indicator] + " "
end
@mutex.synchronize do
print("\e[2K\e[?25l\e[1m#{icon}#{msg}\e[0m\r")
@progress_msg = msg
- @progress_indicator += 1
- @progress_indicator %= PROGRESS_INDICATORS.size
+ if Time.now - @progress_last_update > 0.2
+ @progress_indicator += 1
+ @progress_indicator %= PROGRESS_INDICATORS.size
+ @progress_last_update = Time.now
+ end
end
Thread.new do
sleep(0.05)
progress(msg + ".", nil) if @progress_msg == msg
end