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
-
#highlight=(value) ⇒ Object
explicitly set highlighting [true/false/nil].
-
#highlight? ⇒ Boolean
highlight output using control characters.
- #io_tty? ⇒ Boolean
-
#note=(note) ⇒ Object
set note.
-
#running? ⇒ Boolean
check if progress was started.
-
#set(new_current, note = nil, &block) ⇒ Object
set value of current progress.
-
#start(total = nil, title = nil) ⇒ Object
start progress indication.
-
#stay_on_line=(value) ⇒ Object
explicitly set staying on one line [true/false/nil].
-
#stay_on_line? ⇒ Boolean
stay on one line.
-
#step(step = nil, note = nil, &block) ⇒ Object
step current progress.
-
#stop ⇒ Object
stop progress.
-
#terminal_title=(value) ⇒ Object
explicitly set showing progress in terminal title [true/false/nil].
-
#terminal_title? ⇒ Boolean
show progress in terminal title.
-
#without_beeper ⇒ Object
don’t refresh progress (eta) periodically for the duration of the block.
Instance Attribute Details
#io ⇒ Object
101 102 103 |
# File 'lib/progress/class_methods.rb', line 101 def io @io ||= $stderr end |
Class Method Details
.extended(klass) ⇒ Object
7 8 9 |
# File 'lib/progress/class_methods.rb', line 7 def self.extended(klass) klass.instance_variable_set(:@lock, Mutex.new) end |
Instance Method Details
#highlight=(value) ⇒ Object
explicitly set highlighting [true/false/nil]
85 86 87 |
# File 'lib/progress/class_methods.rb', line 85 def highlight=(value) @highlight = true && value end |
#highlight? ⇒ Boolean
highlight output using control characters
80 81 82 |
# File 'lib/progress/class_methods.rb', line 80 def highlight? @highlight.nil? ? io_tty? : @highlight end |
#io_tty? ⇒ Boolean
105 106 107 |
# File 'lib/progress/class_methods.rb', line 105 def io_tty? io.tty? || ENV['PROGRESS_TTY'] end |
#note=(note) ⇒ Object
set note
63 64 65 66 67 |
# File 'lib/progress/class_methods.rb', line 63 def note=(note) return unless running? @levels.last.note = note end |
#running? ⇒ Boolean
check if progress was started
58 59 60 |
# File 'lib/progress/class_methods.rb', line 58 def running? @levels && !@levels.empty? end |
#set(new_current, note = nil, &block) ⇒ Object
set value of current progress
36 37 38 39 40 41 42 43 44 |
# File 'lib/progress/class_methods.rb', line 36 def set(new_current, note = nil, &block) if running? ret = @levels.last.set(new_current, note, &block) ret elsif block yield end end |
#start(total = nil, title = nil) ⇒ Object
start progress indication
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/progress/class_methods.rb', line 12 def start(total = nil, title = nil) init(total, title) 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]
75 76 77 |
# File 'lib/progress/class_methods.rb', line 75 def stay_on_line=(value) @stay_on_line = true && value end |
#stay_on_line? ⇒ Boolean
stay on one line
70 71 72 |
# File 'lib/progress/class_methods.rb', line 70 def stay_on_line? @stay_on_line.nil? ? io_tty? : @stay_on_line end |
#step(step = nil, note = nil, &block) ⇒ Object
step current progress
25 26 27 28 29 30 31 32 33 |
# File 'lib/progress/class_methods.rb', line 25 def step(step = nil, note = nil, &block) if running? ret = @levels.last.step(step, note, &block) ret elsif block yield end end |
#stop ⇒ Object
stop progress
47 48 49 50 51 52 53 54 55 |
# File 'lib/progress/class_methods.rb', line 47 def stop return unless running? if @levels.length == 1 force: true, finish: true stop_beeper end @levels.pop end |
#terminal_title=(value) ⇒ Object
explicitly set showing progress in terminal title [true/false/nil]
95 96 97 |
# File 'lib/progress/class_methods.rb', line 95 def terminal_title=(value) @terminal_title = true && value end |
#terminal_title? ⇒ Boolean
show progress in terminal title
90 91 92 |
# File 'lib/progress/class_methods.rb', line 90 def terminal_title? @terminal_title.nil? ? io_tty? : @terminal_title end |
#without_beeper ⇒ Object
don’t refresh progress (eta) periodically for the duration of the block
110 111 112 113 114 115 116 |
# File 'lib/progress/class_methods.rb', line 110 def without_beeper old_state = @without_beeper @without_beeper = true yield ensure @without_beeper = old_state end |