infobar 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.utilsrc +26 -0
- data/Gemfile +5 -0
- data/README.md +38 -0
- data/Rakefile +28 -0
- data/TODO.md +22 -0
- data/VERSION +1 -0
- data/infobar.gemspec +52 -0
- data/lib/infobar.rb +139 -0
- data/lib/infobar/counter.rb +101 -0
- data/lib/infobar/display.rb +131 -0
- data/lib/infobar/duration.rb +15 -0
- data/lib/infobar/fancy_interface.rb +26 -0
- data/lib/infobar/frequency.rb +33 -0
- data/lib/infobar/input_output.rb +25 -0
- data/lib/infobar/message.rb +154 -0
- data/lib/infobar/number.rb +10 -0
- data/lib/infobar/spinner.rb +51 -0
- data/lib/infobar/timer.rb +47 -0
- data/lib/infobar/version.rb +8 -0
- data/spec/config/infobar.yml +20 -0
- data/spec/infobar/config_spec.rb +27 -0
- data/spec/infobar/counter_spec.rb +135 -0
- data/spec/infobar/display_spec.rb +71 -0
- data/spec/infobar/duration_spec.rb +12 -0
- data/spec/infobar/frequency_spec.rb +44 -0
- data/spec/infobar/input_output_spec.rb +34 -0
- data/spec/infobar/message_spec.rb +70 -0
- data/spec/infobar/number_spec.rb +12 -0
- data/spec/infobar/spinner_spec.rb +37 -0
- data/spec/infobar/timer_spec.rb +31 -0
- data/spec/infobar_spec.rb +148 -0
- data/spec/spec_helper.rb +12 -0
- metadata +210 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: efa40cb4c4b4763c56296e96a24358e46cef3a73
|
4
|
+
data.tar.gz: 3350e61f29a337276e17b84d1f3ee81eb91fc78f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '079be8e48a1234be9d2e018939cb34fba2b87b84ad1c55e78ccee3ee7c19c67d93dad11f31c1117e8a5151671bd1e8d5eb7965c3c5aeedd898c88b775f9d9b81'
|
7
|
+
data.tar.gz: 00fc996234f4c637db4b1f0c79cd193e54eb49a3f6d2032f4bc8dd4b837753ba9619cf1aa4bfeab59f3c6e3c35c93fbed073bf6c8a1f281a0bc8909c1c403465
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.utilsrc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# vim: set ft=ruby:
|
2
|
+
|
3
|
+
search do
|
4
|
+
prune_dirs /\A(\.svn|\.git|CVS|tmp|tags|coverage|pkg)\z/
|
5
|
+
skip_files /(\A\.|\.sw[pon]\z|\.(log|fnm|jpg|jpeg|png|pdf|svg)\z|tags|~\z)/i
|
6
|
+
end
|
7
|
+
|
8
|
+
discover do
|
9
|
+
prune_dirs /\A(\.svn|\.git|CVS|tmp|tags|coverage|pkg)\z/
|
10
|
+
skip_files /(\A\.|\.sw[pon]\z|\.log\z|~\z)/
|
11
|
+
binary false
|
12
|
+
end
|
13
|
+
|
14
|
+
strip_spaces do
|
15
|
+
prune_dirs /\A(\..*|CVS|pkg)\z/
|
16
|
+
skip_files /(\A\.|\.sw[pon]\z|\.log\z|~\z)/
|
17
|
+
end
|
18
|
+
|
19
|
+
probe do
|
20
|
+
test_framework :rspec
|
21
|
+
#include_dirs 'features'
|
22
|
+
end
|
23
|
+
|
24
|
+
ssh_tunnel do
|
25
|
+
terminal_multiplexer :tmux
|
26
|
+
end
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Infobar
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
Display progress of computations and additional information to the terminal.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
# gem install infobar
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
> Infobar(total: 23)
|
14
|
+
░░░░░░░░░░ Infobar 6/23 in 00:00:05, ETA 00:00:17 @17:43:37 –
|
15
|
+
> 23.times { +infobar; sleep 1 }
|
16
|
+
░░░░░░░░░░░Infobar 23/23 in 00:00:22, ETA 00:00:00 @17:43:37 ✓░░░░░░░░░░
|
17
|
+
|
18
|
+
or alternatively
|
19
|
+
|
20
|
+
> (1..23).with_infobar.each { |i| +infobar; sleep 1 }
|
21
|
+
|
22
|
+
## Changes
|
23
|
+
|
24
|
+
* 2017-02-08 Release 0.0.0
|
25
|
+
|
26
|
+
## Download
|
27
|
+
|
28
|
+
The homepage of this library is located at
|
29
|
+
|
30
|
+
* https://github.com/flori/infobar
|
31
|
+
|
32
|
+
## Author
|
33
|
+
|
34
|
+
[Florian Frank](mailto:flori@ping.de)
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
This software is licensed under the Apache 2.0 license.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# vim: set filetype=ruby et sw=2 ts=2:
|
2
|
+
|
3
|
+
require 'gem_hadar'
|
4
|
+
|
5
|
+
GemHadar do
|
6
|
+
name 'infobar'
|
7
|
+
author 'Florian Frank'
|
8
|
+
email 'flori@ping.de'
|
9
|
+
homepage "http://flori.github.com/#{name}"
|
10
|
+
summary 'Gem to display information about computations.'
|
11
|
+
description 'This gem displays progress of computations and additional information to the terminal.'
|
12
|
+
module_type :class
|
13
|
+
test_dir 'spec'
|
14
|
+
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc',
|
15
|
+
'.AppleDouble', 'tags', '.byebug_history', '.DS_Store', 'errors.lst'
|
16
|
+
readme 'README.md'
|
17
|
+
title "#{name.camelize}"
|
18
|
+
|
19
|
+
required_ruby_version '>= 2.3'
|
20
|
+
dependency 'tins', '~> 1.0', '>= 1.13.2'
|
21
|
+
dependency 'term-ansicolor', '~> 1.4'
|
22
|
+
dependency 'complex_config', '~> 0.10'
|
23
|
+
development_dependency 'rake'
|
24
|
+
development_dependency 'simplecov'
|
25
|
+
development_dependency 'rspec'
|
26
|
+
end
|
27
|
+
|
28
|
+
task :default => :spec
|
data/TODO.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# TODO
|
2
|
+
|
3
|
+
- add color gradients?
|
4
|
+
- cumulative counters to summarize several progress bars
|
5
|
+
- more documentation, lol
|
6
|
+
|
7
|
+
## DONE
|
8
|
+
|
9
|
+
- units
|
10
|
+
- configuration file?
|
11
|
+
- add finished directive
|
12
|
+
- add nicer `Message#to_s` method
|
13
|
+
- add output methods that clear b4 printing to allow output while progressing
|
14
|
+
- elapsed time as duration
|
15
|
+
- ETA as duration
|
16
|
+
- ETA as datetime
|
17
|
+
- rate
|
18
|
+
- better average idea
|
19
|
+
- Update Frequency
|
20
|
+
- spinner animation
|
21
|
+
- newline method
|
22
|
+
- Easily switch on/off output
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/infobar.gemspec
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# stub: infobar 0.0.0 ruby lib
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "infobar".freeze
|
6
|
+
s.version = "0.0.0"
|
7
|
+
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib".freeze]
|
10
|
+
s.authors = ["Florian Frank".freeze]
|
11
|
+
s.date = "2017-02-08"
|
12
|
+
s.description = "This gem displays progress of computations and additional information to the terminal.".freeze
|
13
|
+
s.email = "flori@ping.de".freeze
|
14
|
+
s.extra_rdoc_files = ["README.md".freeze, "lib/infobar.rb".freeze, "lib/infobar/counter.rb".freeze, "lib/infobar/display.rb".freeze, "lib/infobar/duration.rb".freeze, "lib/infobar/fancy_interface.rb".freeze, "lib/infobar/frequency.rb".freeze, "lib/infobar/input_output.rb".freeze, "lib/infobar/message.rb".freeze, "lib/infobar/number.rb".freeze, "lib/infobar/spinner.rb".freeze, "lib/infobar/timer.rb".freeze, "lib/infobar/version.rb".freeze]
|
15
|
+
s.files = [".gitignore".freeze, ".rspec".freeze, ".utilsrc".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "TODO.md".freeze, "VERSION".freeze, "infobar.gemspec".freeze, "lib/infobar.rb".freeze, "lib/infobar/counter.rb".freeze, "lib/infobar/display.rb".freeze, "lib/infobar/duration.rb".freeze, "lib/infobar/fancy_interface.rb".freeze, "lib/infobar/frequency.rb".freeze, "lib/infobar/input_output.rb".freeze, "lib/infobar/message.rb".freeze, "lib/infobar/number.rb".freeze, "lib/infobar/spinner.rb".freeze, "lib/infobar/timer.rb".freeze, "lib/infobar/version.rb".freeze, "spec/config/infobar.yml".freeze, "spec/infobar/config_spec.rb".freeze, "spec/infobar/counter_spec.rb".freeze, "spec/infobar/display_spec.rb".freeze, "spec/infobar/duration_spec.rb".freeze, "spec/infobar/frequency_spec.rb".freeze, "spec/infobar/input_output_spec.rb".freeze, "spec/infobar/message_spec.rb".freeze, "spec/infobar/number_spec.rb".freeze, "spec/infobar/spinner_spec.rb".freeze, "spec/infobar/timer_spec.rb".freeze, "spec/infobar_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
16
|
+
s.homepage = "http://flori.github.com/infobar".freeze
|
17
|
+
s.rdoc_options = ["--title".freeze, "Infobar".freeze, "--main".freeze, "README.md".freeze]
|
18
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.3".freeze)
|
19
|
+
s.rubygems_version = "2.6.8".freeze
|
20
|
+
s.summary = "Gem to display information about computations.".freeze
|
21
|
+
s.test_files = ["spec/infobar/config_spec.rb".freeze, "spec/infobar/counter_spec.rb".freeze, "spec/infobar/display_spec.rb".freeze, "spec/infobar/duration_spec.rb".freeze, "spec/infobar/frequency_spec.rb".freeze, "spec/infobar/input_output_spec.rb".freeze, "spec/infobar/message_spec.rb".freeze, "spec/infobar/number_spec.rb".freeze, "spec/infobar/spinner_spec.rb".freeze, "spec/infobar/timer_spec.rb".freeze, "spec/infobar_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
s.specification_version = 4
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
|
28
|
+
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
29
|
+
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
30
|
+
s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
|
31
|
+
s.add_runtime_dependency(%q<tins>.freeze, [">= 1.13.2", "~> 1.0"])
|
32
|
+
s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.4"])
|
33
|
+
s.add_runtime_dependency(%q<complex_config>.freeze, ["~> 0.10"])
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
|
36
|
+
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
37
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
38
|
+
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
39
|
+
s.add_dependency(%q<tins>.freeze, [">= 1.13.2", "~> 1.0"])
|
40
|
+
s.add_dependency(%q<term-ansicolor>.freeze, ["~> 1.4"])
|
41
|
+
s.add_dependency(%q<complex_config>.freeze, ["~> 0.10"])
|
42
|
+
end
|
43
|
+
else
|
44
|
+
s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
|
45
|
+
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
46
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
47
|
+
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
48
|
+
s.add_dependency(%q<tins>.freeze, [">= 1.13.2", "~> 1.0"])
|
49
|
+
s.add_dependency(%q<term-ansicolor>.freeze, ["~> 1.4"])
|
50
|
+
s.add_dependency(%q<complex_config>.freeze, ["~> 0.10"])
|
51
|
+
end
|
52
|
+
end
|
data/lib/infobar.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'tins/xt'
|
2
|
+
require 'complex_config'
|
3
|
+
|
4
|
+
class Infobar
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'infobar/version'
|
8
|
+
require 'infobar/counter'
|
9
|
+
require 'infobar/display'
|
10
|
+
require 'infobar/message'
|
11
|
+
require 'infobar/fancy_interface'
|
12
|
+
require 'infobar/input_output'
|
13
|
+
|
14
|
+
class Infobar
|
15
|
+
class << self
|
16
|
+
prepend Tins::Delegate
|
17
|
+
end
|
18
|
+
include Tins::SexySingleton
|
19
|
+
include Infobar::FancyInterface
|
20
|
+
prepend Infobar::InputOutput
|
21
|
+
include ComplexConfig::Provider::Shortcuts
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@counter = Infobar::Counter.new
|
25
|
+
@display = Infobar::Display.new
|
26
|
+
reset
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.display
|
30
|
+
Infobar.instance.display
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_reader :message
|
34
|
+
|
35
|
+
attr_reader :counter
|
36
|
+
|
37
|
+
attr_reader :display
|
38
|
+
|
39
|
+
attr_accessor :label
|
40
|
+
|
41
|
+
delegate :started?, to: :@counter
|
42
|
+
|
43
|
+
delegate :done?, to: :@counter
|
44
|
+
|
45
|
+
delegate :finished?, to: :@counter
|
46
|
+
|
47
|
+
delegate :show?, to: :@display
|
48
|
+
|
49
|
+
delegate :show=, to: :@display
|
50
|
+
|
51
|
+
delegate :style=, to: :@display
|
52
|
+
|
53
|
+
def call(
|
54
|
+
total:,
|
55
|
+
current: 0,
|
56
|
+
label: cc.infobar?&.label || 'Infobar',
|
57
|
+
message: cc.infobar?&.message?&.to_h,
|
58
|
+
show: cc.infobar?&.show?,
|
59
|
+
style: cc.infobar?&.style?&.to_h,
|
60
|
+
frequency: cc.infobar?&.frequency?,
|
61
|
+
update: false,
|
62
|
+
finish: nil
|
63
|
+
)
|
64
|
+
self.label = label
|
65
|
+
@counter.reset(total: total, current: current)
|
66
|
+
@message = convert_to_message(message)
|
67
|
+
show.nil? or self.show = show
|
68
|
+
if update
|
69
|
+
update(message: @message)
|
70
|
+
else
|
71
|
+
@display.reset
|
72
|
+
end
|
73
|
+
frequency.nil? or display.frequency = frequency
|
74
|
+
style.nil? or self.style = style
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
def reset
|
79
|
+
@message = convert_to_message('%l %c/%t in %te, ETA %e @%E %s')
|
80
|
+
@counter.reset(total: 0, current: 0)
|
81
|
+
@display.reset
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
85
|
+
def update(message: nil)
|
86
|
+
@message = convert_to_message(message)
|
87
|
+
@display.update(message: @message, progressed: @counter.progressed)
|
88
|
+
self
|
89
|
+
end
|
90
|
+
|
91
|
+
def progress(by: 1, message: nil, finish: true, force: false)
|
92
|
+
@counter.progress(by: by)
|
93
|
+
@message = convert_to_message(message)
|
94
|
+
@display.update(message: @message, force: force, progressed: @counter.progressed)
|
95
|
+
finish && @counter.done? and finish(message: finish)
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
def finish(message: nil)
|
100
|
+
@counter.finish
|
101
|
+
@message = convert_to_message(message)
|
102
|
+
@display.update(message: @message, force: true, progressed: @counter.progressed)
|
103
|
+
self
|
104
|
+
end
|
105
|
+
|
106
|
+
def convert_to_message(message)
|
107
|
+
case message
|
108
|
+
when Message
|
109
|
+
message
|
110
|
+
when Hash
|
111
|
+
Message.new(message)
|
112
|
+
when String
|
113
|
+
Message.new format: message
|
114
|
+
else
|
115
|
+
@message
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def Infobar(**opts)
|
121
|
+
Infobar.(**opts)
|
122
|
+
end
|
123
|
+
|
124
|
+
class ::Object
|
125
|
+
def infobar
|
126
|
+
::Infobar.instance
|
127
|
+
end
|
128
|
+
|
129
|
+
def with_infobar(**opts)
|
130
|
+
case
|
131
|
+
when total = opts[:total].ask_and_send(:to_sym)
|
132
|
+
opts[:total] = __send__(total)
|
133
|
+
when opts[:total].nil?
|
134
|
+
opts[:total] = size
|
135
|
+
end
|
136
|
+
Infobar.(**opts)
|
137
|
+
self
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'infobar/timer'
|
2
|
+
|
3
|
+
class Infobar::Counter
|
4
|
+
class <<
|
5
|
+
prepend Tins::Delegate
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
reset
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :current
|
13
|
+
|
14
|
+
attr_reader :total
|
15
|
+
|
16
|
+
def reset(total: 0, current: 0)
|
17
|
+
@current = current
|
18
|
+
@total = total
|
19
|
+
@start = nil
|
20
|
+
@finished = false
|
21
|
+
@timer = Infobar::Timer.new
|
22
|
+
end
|
23
|
+
|
24
|
+
delegate :rate, to: :@timer
|
25
|
+
|
26
|
+
delegate :average_time, to: :@timer
|
27
|
+
|
28
|
+
def started?
|
29
|
+
@start
|
30
|
+
end
|
31
|
+
|
32
|
+
def finished?
|
33
|
+
@finished
|
34
|
+
end
|
35
|
+
|
36
|
+
def finish
|
37
|
+
@finished = Time.now
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def progress(by: 1)
|
42
|
+
if !finished? && by >= 1
|
43
|
+
now = Time.now
|
44
|
+
@start ||= now
|
45
|
+
@timer.add(now, by)
|
46
|
+
@current += by
|
47
|
+
end
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
def done?
|
52
|
+
@current >= @total
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_go
|
56
|
+
[ total - current, 0 ].max
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_go?
|
60
|
+
to_go.nonzero?
|
61
|
+
end
|
62
|
+
|
63
|
+
def time_remaining
|
64
|
+
if @finished
|
65
|
+
0.0
|
66
|
+
else
|
67
|
+
average_time * to_go
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def eta
|
72
|
+
if @finished
|
73
|
+
@finished
|
74
|
+
else
|
75
|
+
Time.now + time_remaining
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def time_elapsed
|
80
|
+
case
|
81
|
+
when @finished && @start
|
82
|
+
@finished - @start
|
83
|
+
when @start
|
84
|
+
Time.now - @start
|
85
|
+
else
|
86
|
+
0.0
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def total_time
|
91
|
+
time_elapsed + time_remaining
|
92
|
+
end
|
93
|
+
|
94
|
+
def progressed
|
95
|
+
if @total.zero?
|
96
|
+
0.0
|
97
|
+
else
|
98
|
+
@current / @total.to_f
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|