Module: Progress::ClassMethods

Included in:
Progress
Defined in:
lib/progress/class_methods.rb

Overview

Class methods of Progress

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ioObject



103
104
105
# File 'lib/progress/class_methods.rb', line 103

def io
  @io ||= $stderr
end

Class Method Details

.extended(klass) ⇒ Object



9
10
11
# File 'lib/progress/class_methods.rb', line 9

def self.extended(klass)
  klass.instance_variable_set(:@lock, Mutex.new)
end

Instance Method Details

#highlight=(value) ⇒ Object

explicitly set highlighting [true/false/nil]



87
88
89
# File 'lib/progress/class_methods.rb', line 87

def highlight=(value)
  @highlight = true && value
end

#highlight?Boolean

highlight output using control characters

Returns:

  • (Boolean)


82
83
84
# File 'lib/progress/class_methods.rb', line 82

def highlight?
  @highlight.nil? ? io_tty? : @highlight
end

#io_tty?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/progress/class_methods.rb', line 107

def io_tty?
  io.tty? || ENV['PROGRESS_TTY']
end

#note=(note) ⇒ Object

set note



65
66
67
68
69
# File 'lib/progress/class_methods.rb', line 65

def note=(note)
  return unless running?

  @levels.last.note = note
end

#running?Boolean

check if progress was started

Returns:

  • (Boolean)


60
61
62
# File 'lib/progress/class_methods.rb', line 60

def running?
  @levels && !@levels.empty?
end

#set(new_current, note = nil, &block) ⇒ Object

set value of current progress



38
39
40
41
42
43
44
45
46
# File 'lib/progress/class_methods.rb', line 38

def set(new_current, note = nil, &block)
  if running?
    ret = @levels.last.set(new_current, note, &block)
    print_message
    ret
  elsif block
    yield
  end
end

#start(total = nil, title = nil) ⇒ Object

start progress indication



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/progress/class_methods.rb', line 14

def start(total = nil, title = nil)
  init(total, title)
  print_message force: true
  return unless block_given?

  begin
    yield
  ensure
    stop
  end
end

#stay_on_line=(value) ⇒ Object

explicitly set staying on one line [true/false/nil]



77
78
79
# File 'lib/progress/class_methods.rb', line 77

def stay_on_line=(value)
  @stay_on_line = true && value
end

#stay_on_line?Boolean

stay on one line

Returns:

  • (Boolean)


72
73
74
# File 'lib/progress/class_methods.rb', line 72

def stay_on_line?
  @stay_on_line.nil? ? io_tty? : @stay_on_line
end

#step(step = nil, note = nil, &block) ⇒ Object

step current progress



27
28
29
30
31
32
33
34
35
# File 'lib/progress/class_methods.rb', line 27

def step(step = nil, note = nil, &block)
  if running?
    ret = @levels.last.step(step, note, &block)
    print_message
    ret
  elsif block
    yield
  end
end

#stopObject

stop progress



49
50
51
52
53
54
55
56
57
# File 'lib/progress/class_methods.rb', line 49

def stop
  return unless running?

  if @levels.length == 1
    print_message force: true, finish: true
    stop_beeper
  end
  @levels.pop
end

#terminal_title=(value) ⇒ Object

explicitly set showing progress in terminal title [true/false/nil]



97
98
99
# File 'lib/progress/class_methods.rb', line 97

def terminal_title=(value)
  @terminal_title = true && value
end

#terminal_title?Boolean

show progress in terminal title

Returns:

  • (Boolean)


92
93
94
# File 'lib/progress/class_methods.rb', line 92

def terminal_title?
  @terminal_title.nil? ? io_tty? : @terminal_title
end

#without_beeperObject

don’t refresh progress (eta) periodically for the duration of the block



112
113
114
115
116
117
118
# File 'lib/progress/class_methods.rb', line 112

def without_beeper
  old_state = @without_beeper
  @without_beeper = true
  yield
ensure
  @without_beeper = old_state
end