tiny_bar 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/tiny_bar.rb +57 -0
- metadata +58 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1de23178d23fd13e12aed7fe01c90f656c90a4e4732f66b9ffc263162d44bd53
|
|
4
|
+
data.tar.gz: 1627c63583a48cfbee2923d7f063423b24f6027025bd2ce55f68bd0f72bac38a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5a4930a5eaa60c4d04ffd6a441a7d3da0ff9234cc90cdd8330739b88958208f4d7b198c9ba485b036e0438b0d804bc7367cb43b7d69ec79b7b3974d9bce5bf8b
|
|
7
|
+
data.tar.gz: e49907e10980599b7c8931846acbe8a5297e0381428f99384cd4bc6800c7480f84038a49b58e09903a731c52a91180540715df00d61ac58650775e7d87189ee7
|
data/lib/tiny_bar.rb
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'tiny_color'
|
|
2
|
+
|
|
3
|
+
# the TinyBar class is used to create a text-based progress bar with various
|
|
4
|
+
# properties like width, background color, foreground color, label, and
|
|
5
|
+
# percent filled.
|
|
6
|
+
#
|
|
7
|
+
# usage:
|
|
8
|
+
# tiny_bar = TinyBar.new # creates a new TinyBar instance
|
|
9
|
+
# tiny_bar.label = 'Progress' # sets the label to 'Progress'
|
|
10
|
+
# tiny_bar.percent_filled = 0.5 # sets the percent filled to 50%
|
|
11
|
+
# tiny_bar.width = 100 # sets the width of the bar to 100
|
|
12
|
+
# tiny_bar.bg_color = :blue # sets the background color to blue
|
|
13
|
+
# tiny_bar.fg_color = :white # sets the foreground color to white
|
|
14
|
+
# puts tiny_bar # prints the TinyBar instance
|
|
15
|
+
#
|
|
16
|
+
# This will print a progress bar of width 100 with a blue background, white
|
|
17
|
+
# foreground, and 'Progress' label filled to 50%.
|
|
18
|
+
class TinyBar
|
|
19
|
+
attr_reader :percent_filled,
|
|
20
|
+
:label
|
|
21
|
+
|
|
22
|
+
attr_accessor :width,
|
|
23
|
+
:bg_color,
|
|
24
|
+
:fg_color
|
|
25
|
+
|
|
26
|
+
def initialize
|
|
27
|
+
@width = 80
|
|
28
|
+
@bg_color = :default
|
|
29
|
+
@fg_color = :default
|
|
30
|
+
@label = ''
|
|
31
|
+
@value = 0
|
|
32
|
+
@percent_filled = 0.0
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def percent_filled=(value)
|
|
36
|
+
@percent_filled = value.clamp(0.0, 1.0).round(2)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def label=(value)
|
|
40
|
+
@label = value.to_s
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def to_s
|
|
44
|
+
full_width_s = label
|
|
45
|
+
.to_s
|
|
46
|
+
.rjust((width / 2) + (label.length / 2))
|
|
47
|
+
.ljust(width)
|
|
48
|
+
|
|
49
|
+
filled_width = (full_width_s.length * percent_filled).round
|
|
50
|
+
unfilled_width = (full_width_s.length - filled_width) - 1
|
|
51
|
+
|
|
52
|
+
left = full_width_s[..filled_width]
|
|
53
|
+
right = unfilled_width > 0 ? full_width_s[-unfilled_width..] : ''
|
|
54
|
+
|
|
55
|
+
"#{left.send(fg_color).send("on_#{bg_color}")}#{right}"
|
|
56
|
+
end
|
|
57
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: tiny_bar
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jeff Lunt
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-08-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: tiny_color
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
description: like a progress bar, but can also be used to measure used capacity of
|
|
28
|
+
something
|
|
29
|
+
email: jefflunt@gmail.com
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- lib/tiny_bar.rb
|
|
35
|
+
homepage: https://github.com/jefflunt/tiny_bar
|
|
36
|
+
licenses:
|
|
37
|
+
- MIT
|
|
38
|
+
metadata: {}
|
|
39
|
+
post_install_message:
|
|
40
|
+
rdoc_options: []
|
|
41
|
+
require_paths:
|
|
42
|
+
- lib
|
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '0'
|
|
53
|
+
requirements: []
|
|
54
|
+
rubygems_version: 3.3.7
|
|
55
|
+
signing_key:
|
|
56
|
+
specification_version: 4
|
|
57
|
+
summary: like a progress bar, but can also be used to measure used capacity of something
|
|
58
|
+
test_files: []
|