Skip to content

more defaults! #204

@gurgeous

Description

@gurgeous

Yes, we are still enjoying ruby progressbar :) Still need defaults! Here's our current monkeypatch, if anyone is interested:

Image
class ProgressBar
  class Base
    DEFAULTS = {
      format: "%j%% %B %c/%u • %e",
      progress_mark: "\e[0;38;5;46m━\e[0m",
      remainder_mark: "\e[0;38;5;237m━\e[0m",
      length: 72,
    }

    alias initialize_without_defaults initialize

    def initialize(options = {}, *args, &block)
      options = DEFAULTS.merge(options || {})
      initialize_without_defaults(options, *args, &block)
    end
  end
end

also a custom Enumerator monkeypatch that includes cursor show/hide the cursor:

class Enumerator
  def with_progressbar(options = {}, &block)
    return enum_for(__method__, options.dup) if !block
    output = options[:output] || ($stdout.isatty ? $stdout : $stderr)
    bar = ProgressBar.create(defaults.merge(options))
    begin
      output.write "\e[?25l"
      each do
        bar.increment
        yield(_1)
      end
    ensure
      output.write "\e[?25h"
    end
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions