class InteractiveLogger::Step

Constants

FAILURE_SYMBOL
LB
PROGRESS_SYMBOLS
RB
SUCCESS_SYMBOL

Public Class Methods

new(str, show_time: true) click to toggle source
# File lib/interactive_logger/step.rb, line 12
def initialize(str, show_time: true)
  @last_str = str
  @start = Time.now
  @show_time = show_time
  @pos = 0
  print_trimmed(in_progress_prefix << str)
end

Public Instance Methods

blank() click to toggle source

Blank out the current line.

# File lib/interactive_logger/step.rb, line 40
def blank
  print "\r"
  if @last_print_msg
    print ' ' * IO.console.winsize[1]
  end
  print "\r"
end
continue(str = nil) click to toggle source
# File lib/interactive_logger/step.rb, line 20
def continue(str = nil)
  @pos += 1
  blank
  @last_str = str if str
  print_trimmed(in_progress_prefix << @last_str)
end
failure(str = nil) click to toggle source
# File lib/interactive_logger/step.rb, line 27
def failure(str = nil)
  blank
  @last_str = str if str
  print_msg(prefix(FAILURE_SYMBOL) << @last_str)
end
repaint() click to toggle source
# File lib/interactive_logger/step.rb, line 48
def repaint
  print @last_print_msg
end
success(str = nil) click to toggle source
# File lib/interactive_logger/step.rb, line 33
def success(str = nil)
  blank
  @last_str = str if str
  print_msg(prefix(SUCCESS_SYMBOL) << @last_str)
end

Private Instance Methods

in_progress_prefix() click to toggle source
# File lib/interactive_logger/step.rb, line 54
def in_progress_prefix
  prefix(PROGRESS_SYMBOLS[@pos % PROGRESS_SYMBOLS.size].yellow)
end
prefix(str) click to toggle source
# File lib/interactive_logger/step.rb, line 58
def prefix(str)
  show_time = ''
  if @show_time
    show_time = Duration.new(Time.now.to_i - @start.to_i)
                        .format(" #{LB} %tmm %ss #{RB}")
  end
  "#{LB} #{str} #{RB}#{show_time} "
end
print_msg(str) click to toggle source
print_trimmed(str) click to toggle source

Trim string to current terminal width and break at newline so it can be replaced rather than causing the same line to print multiple times.

The bulk of this logic is dedicated to counting only printable characters, and ensure we reset the colors afterward.