Git Product home page Git Product logo

progress's Introduction

Gem Version Build Status Rubocop Code Climate Depfu Inch CI

progress

Show progress during console script run.

Installation

gem install progress

Usage

1000.times_with_progress('Counting to 1000') do |i|
  # do something with i
end

or without title:

1000.times_with_progress do |i|
  # do something with i
end

With array:

[1, 2, 3].with_progress('1…2…3').each do |i|
  # still counting
end

.each is optional:

[1, 2, 3].with_progress('1…2…3') do |i|
  # =||=
end

Nested progress

(1..10).with_progress('Outer').map do |a|
  (1..10).with_progress('Middle').map do |b|
    (1..10).with_progress('Inner').map do |c|
      # do something with a, b and c
    end
  end
end

You can also show note:

[1, 2, 3].with_progress do |i|
  Progress.note = i
  sleep 5
end

You can use any enumerable method:

[1, 2, 3].with_progress.map{ |i| 'do stuff' }
[1, 2, 3].with_progress.each_cons(3){ |i| 'do stuff' }
[1, 2, 3].with_progress.each_slice(2){ |i| 'do stuff' }
# …

Any enumerable will work:

(1..100).with_progress('Wait') do |i|
  # ranges are good
end

Dir.new('.').with_progress do |path|
  # check path
end

NOTE: progress gets number of objects using length, size, to_a.length or just inject and if used on objects which needs rewind (like opened File), cycle itself will not work.

Use simple blocks:

symbols = []
Progress.start('Input 100 symbols', 100) do
  while symbols.length < 100
    input = gets.scan(/\S/)
    symbols += input
    Progress.step input.length
  end
end

or just

symbols = []
Progress('Input 100 symbols', 100) do
  while symbols.length < 100
    input = gets.scan(/\S/)
    symbols += input
    Progress.step input.length
  end
end

NOTE: you will get WRONG progress if you use something like this:

10.times_with_progress('A') do |time|
  10.times_with_progress('B') do
    # code
  end
  10.times_with_progress('C') do
    # code
  end
end

But you can use this:

10.times_with_progress('A') do |time|
  Progress.step 5 do
    10.times_with_progress('B') do
      # code
    end
  end
  Progress.step 5 do
    10.times_with_progress('C') do
      # code
    end
  end
end

Or if you know that B runs 9 times faster than C:

10.times_with_progress('A') do |time|
  Progress.step 1 do
    10.times_with_progress('B') do
      # code
    end
  end
  Progress.step 9 do
    10.times_with_progress('C') do
      # code
    end
  end
end

Copyright (c) 2008-2021 Ivan Kuchin. See LICENSE.txt for details.

progress's People

Contributors

amatsuda avatar katsuma avatar olleolleolle avatar toy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

progress's Issues

Memory leak when processing files.

Dir.glob("some.file.*").each.with_progress do |file|
  file.each.with_progress |line|
    puts line
  end
end

This will cause a memory leak. I am not sure if the outer loop is necessary to casue the leak.

Option to redirect to stdout

Currently, I have to monkey patch it like this:

module ProgressClassMethods
  def io
    $stdout
  end
end
Progress.send(:extend, ProgressClassMethods)

Is there a way to override io method without monkey patching?

Stack level too deep

/usr/local/rvm/gems/ruby-1.9.2-p290/bundler/gems/progress-46b34854f62c/lib/progress/with_progress.rb:82: stack level too deep (SystemStackError)

I am not sure at the moment that this is a Progress error. However this is the one thing I've got from the stack trace. BTW - I am not posting to @djstrong repo, although this is from his fork, in order to keep issues in one place.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.