class Bundleup::Logger

Attributes

spinner[R]
stderr[R]

Public Class Methods

new(stdin: $stdin, stdout: $stdout, stderr: $stderr) click to toggle source
# File lib/bundleup/logger.rb, line 9
def initialize(stdin: $stdin, stdout: $stdout, stderr: $stderr)
  @stdin = stdin
  @stdout = stdout
  @stderr = stderr
  @spinner = %w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏].cycle
end

Public Instance Methods

attention(message) click to toggle source
# File lib/bundleup/logger.rb, line 24
def attention(message)
  puts Colors.yellow(message)
end
clear_line() click to toggle source
# File lib/bundleup/logger.rb, line 33
def clear_line
  print "\r".ljust(console_width - 1)
  print "\r"
end
confirm?(question) click to toggle source
# File lib/bundleup/logger.rb, line 28
def confirm?(question)
  print Colors.yellow(question.sub(/\??\z/, " [Yn]? "))
  gets =~ /^($|y)/i
end
error(message) click to toggle source
# File lib/bundleup/logger.rb, line 20
def error(message)
  stderr.puts Colors.red("ERROR: #{message}")
end
ok(message) click to toggle source
# File lib/bundleup/logger.rb, line 16
def ok(message)
  puts Colors.green("✔ #{message}")
end
while_spinning(message, &block) click to toggle source
# File lib/bundleup/logger.rb, line 38
def while_spinning(message, &block)
  thread = Thread.new(&block)
  thread.report_on_exception = false
  message = message.ljust(console_width - 2)
  print "\r#{Colors.blue([spinner.next, message].join(' '))}" until wait_for_exit(thread, 0.1)
  thread.value
end

Private Instance Methods

console_width() click to toggle source
# File lib/bundleup/logger.rb, line 50
def console_width
  width = IO.console.winsize.last if tty?
  width.to_i.positive? ? width : 80
end
wait_for_exit(thread, seconds) click to toggle source
# File lib/bundleup/logger.rb, line 55
def wait_for_exit(thread, seconds)
  thread.join(seconds)
rescue StandardError
  # Sanity check. If we get an exception, the thread should be dead.
  raise if thread.alive?

  thread
end