fwolfst / infobar

Gem to display information about computations.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Infobar

Description

Display progress of computations and additional information to the terminal.

Installation

# gem install infobar

Usage

Basic

In its simplest form, Infobar just shows progress measured in steps, where the "result" of each iteration does not matter.

> Infobar(total: 23)
░░░░░░░░░░ Infobar 6/23 in 00:00:05, ETA 00:00:17 @17:43:37 –
> 23.times { +infobar; sleep 1 }
░░░░░░░░░░░Infobar 23/23 in 00:00:22, ETA 00:00:00 @17:43:37 ✓░░░░░░░░░░

or alternatively

> (1..23).with_infobar.each { |i| +infobar; sleep 1 }

With success/failure count

You can use +infobar and -infobar to progress, but indicate a Success/Failure. Infobar will count these.

(1..23).with_infobar.each do |value|
  # Expensive computation. For illustration, even numbers succeed, others fail
  if value.even?
    +infobar
  else
    -infobar
  end
end

# Output difficult to reproduce here, will indicate colored bar if possible.

With arbitrary result count

Infobar can also count arbitrary results.

(1..23).with_infobar.each do |value|
  # Expensive computation. For illustration, classify by modulo %3
  result = value % 3
  infobar.progress(as: result)
end

puts infobar.counter.as
# {nil=>0, 1=>8, 2=>8, 0=>7}

Changes

  • 2019-04-11 Release 0.6.1
  • Counter string representation shows results now.
  • 2019-01-31 Release 0.6.0
  • Allow progressing with - as false.
  • 2018-11-01 Release 0.5.1

    • Allow busy bar message to be overwritten.
  • 2018-03-05 Release 0.5.0

    • Allow counter values to be formatted with units.
  • 2017-12-08 Release 0.4.0

    • Automatically iterate when with_infobar is passed a block.
  • 2017-06-29 Release 0.3.0

    • Nicely format large numbers the Ruby way
  • 2017-05-24 Release 0.2.0

    • Allow setting of input/output on initial call.

  • 2017-03-24 Release 0.0.6

    • Add busybar functionality via Infobar.busy { … } call
  • 2017-03-10 Release 0.0.5

    • Always provide a default unit for rate display, 'i/s' for "items per second".
  • 2017-03-10 Release 0.0.4

    • Fix problem b/c at the beginning there might not be a valid rate.
  • 2017-03-09 Release 0.0.3

    • Reset frequency after calling clear. This means after calling output methods the next update will be forced.
  • 2017-02-10 Release 0.0.2

    • Add trend arrow to rate directive
  • 2017-02-08 Release 0.0.1

    • Allow disabling of delegated output via infobar.show = false
  • 2017-02-08 Release 0.0.0

    • Initial release

Download

The homepage of this library is located at

Author

Florian Frank

License

This software is licensed under the Apache 2.0 license.

About

Gem to display information about computations.

License:Apache License 2.0


Languages

Language:Ruby 100.0%