Class: Infobar
- Extended by:
- Tins::Delegate
- Includes:
- ComplexConfig::Provider::Shortcuts, FancyInterface, InputOutput, Singleton
- Defined in:
- lib/infobar.rb,
lib/infobar.rb,
lib/infobar/version.rb
Defined Under Namespace
Modules: FancyInterface, InputOutput Classes: Counter, Display, Duration, FIFO, Frequency, Message, Number, Rate, Spinner, Timer, Trend
Constant Summary collapse
- VERSION =
Infobar version
'0.8.1'
- VERSION_ARRAY =
:nodoc:
VERSION.split('.').map(&:to_i)
- VERSION_MAJOR =
:nodoc:
VERSION_ARRAY[0]
- VERSION_MINOR =
:nodoc:
VERSION_ARRAY[1]
- VERSION_BUILD =
:nodoc:
VERSION_ARRAY[2]
Instance Attribute Summary collapse
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
-
#display ⇒ Object
readonly
Returns the value of attribute display.
-
#label ⇒ Object
Returns the value of attribute label.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Class Method Summary collapse
- .busy(**opts, &block) ⇒ Object
- .call(**opts) ⇒ Object
- .convert_to_message(message) ⇒ Object
- .display ⇒ Object
Instance Method Summary collapse
- #busy(frames: :circle1, **opts, &block) ⇒ Object
- #call(total:, current: 0, label: cc.infobar?&.label || 'Infobar', message: cc.infobar?&.message?&.to_h, show: cc.infobar?&.show?, style: cc.infobar?&.style?&.to_h&.symbolize_keys_recursive, as_styles: cc.infobar?&.as_styles?&.to_h&.symbolize_keys_recursive, frequency: cc.infobar?&.frequency?, update: false, input: $stdin, output: $stdout) ⇒ Object
- #convert_to_message(message) ⇒ Object
- #finish(message: nil) ⇒ Object
-
#initialize ⇒ Infobar
constructor
A new instance of Infobar.
- #progress(by: 1, as: nil, message: nil, finish: true, force: false) ⇒ Object
- #reset(display: true) ⇒ Object
- #update(message: nil, force: true) ⇒ Object
Methods included from FancyInterface
#+, #+@, #-, #-@, #<<, #add, #coerce, #~
Methods included from InputOutput
Constructor Details
Instance Attribute Details
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
36 37 38 |
# File 'lib/infobar.rb', line 36 def counter @counter end |
#display ⇒ Object (readonly)
Returns the value of attribute display.
38 39 40 |
# File 'lib/infobar.rb', line 38 def display @display end |
#label ⇒ Object
Returns the value of attribute label.
40 41 42 |
# File 'lib/infobar.rb', line 40 def label @label end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
34 35 36 |
# File 'lib/infobar.rb', line 34 def @message end |
Class Method Details
.busy(**opts, &block) ⇒ Object
93 94 95 |
# File 'lib/infobar.rb', line 93 def self.busy(**opts, &block) instance.busy(**opts, &block) end |
.call(**opts) ⇒ Object
60 61 62 |
# File 'lib/infobar.rb', line 60 def self.call(**opts) instance.call(**opts) end |
.convert_to_message(message) ⇒ Object
146 147 148 |
# File 'lib/infobar.rb', line 146 def self.() instance.() end |
.display ⇒ Object
30 31 32 |
# File 'lib/infobar.rb', line 30 def self.display .display end |
Instance Method Details
#busy(frames: :circle1, **opts, &block) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/infobar.rb', line 97 def busy(frames: :circle1, **opts, &block) block_given? or raise ArgumentError, 'block is required as an argument' duration = opts.delete(:sleep) || 0.1 reset call(**opts | { total: Float::INFINITY, message: { format: ' %l %te %s ', '%s' => { frames: frames } }, }) ib = Thread.new { loop do + sleep duration end } r = nil t = Thread.new { r = yield } t.join ib.kill r end |
#call(total:, current: 0, label: cc.infobar?&.label || 'Infobar', message: cc.infobar?&.message?&.to_h, show: cc.infobar?&.show?, style: cc.infobar?&.style?&.to_h&.symbolize_keys_recursive, as_styles: cc.infobar?&.as_styles?&.to_h&.symbolize_keys_recursive, frequency: cc.infobar?&.frequency?, update: false, input: $stdin, output: $stdout) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/infobar.rb', line 64 def call( total:, current: 0, label: cc.&.label || 'Infobar', message: cc.&.&.to_h, show: cc.&.show?, style: cc.&.style?&.to_h&.symbolize_keys_recursive, as_styles: cc.&.as_styles?&.to_h&.symbolize_keys_recursive, frequency: cc.&.frequency?, update: false, input: $stdin, output: $stdout ) self.label = label counter.reset(total: total, current: current) display.reset clear: false @message = ( .full? || '%l %c/%t in %te, ETA %e @%E %s' ) show.nil? or self.show = show frequency.nil? or display.frequency = frequency style.nil? or self.style = style self.as_styles = as_styles self.input = input self.output = output update and update(message: @message, force: true) self end |
#convert_to_message(message) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/infobar.rb', line 150 def () case when Message when Hash Message.new() when String Message.new({format: }) else @message end end |
#finish(message: nil) ⇒ Object
139 140 141 142 143 144 |
# File 'lib/infobar.rb', line 139 def finish(message: nil) counter.finish @message = () display.update(message: @message, force: true, counter: counter) self end |
#progress(by: 1, as: nil, message: nil, finish: true, force: false) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/infobar.rb', line 131 def progress(by: 1, as: nil, message: nil, finish: true, force: false) counter.progress(by: by, as: as) @message = () display.update(message: @message, force: force, counter: counter) finish && counter.done? and finish(message: finish) self end |
#reset(display: true) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/infobar.rb', line 118 def reset(display: true) @message = ('%l %c/%t in %te, ETA %e @%E %s') counter.reset(total: 0, current: 0) display and self.display.reset self end |
#update(message: nil, force: true) ⇒ Object
125 126 127 128 129 |
# File 'lib/infobar.rb', line 125 def update(message: nil, force: true) @message = () display.update(message: @message, counter: counter, force: force) self end |