Class: InteractiveLogger::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/interactive_logger/step.rb

Constant Summary collapse

PROGRESS_SYMBOLS =
%w(- \\ | /)
FAILURE_SYMBOL =
'✗'.red
SUCCESS_SYMBOL =
'✓'.green
LB =
'['.light_black
RB =
']'.light_black

Instance Method Summary collapse

Constructor Details

#initialize(str, show_time: true) ⇒ Step

Returns a new instance of Step.



12
13
14
15
16
17
18
# 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

Instance Method Details

#blankObject

Blank out the current line.



40
41
42
43
44
45
46
# 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) ⇒ Object



20
21
22
23
24
25
# 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) ⇒ Object



27
28
29
30
31
# 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

#repaintObject



48
49
50
# File 'lib/interactive_logger/step.rb', line 48

def repaint
  print @last_print_msg
end

#success(str = nil) ⇒ Object



33
34
35
36
37
# 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