pycoolprogressbar 0.1.0__py3-none-any.whl
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.
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
from yet_another_ansi_lib import ansi as nc
|
|
2
|
+
from sys import stdout
|
|
3
|
+
from shutil import get_terminal_size
|
|
4
|
+
import time
|
|
5
|
+
from typing import Literal
|
|
6
|
+
|
|
7
|
+
COLORS_LIST = list(nc.ANSI_CODES)
|
|
8
|
+
|
|
9
|
+
COLORS = Literal[
|
|
10
|
+
'black', 'red', 'green', 'yellow', 'blue', 'purple', 'cyan', 'white',
|
|
11
|
+
'intense_black', 'intense_red', 'intense_green', 'intense_yellow',
|
|
12
|
+
'intense_blue', 'intense_purple', 'intense_cyan', 'intense_white',
|
|
13
|
+
'bg_black', 'bg_red', 'bg_green', 'bg_yellow', 'bg_blue', 'bg_purple', 'bg_cyan', 'bg_white',
|
|
14
|
+
'bg_intense_black', 'bg_intense_red', 'bg_intense_green', 'bg_intense_yellow',
|
|
15
|
+
'bg_intense_blue', 'bg_intense_purple', 'bg_intense_cyan', 'bg_intense_white',
|
|
16
|
+
'bold', 'underline', 'italic', 'strikethrough', 'blink', 'reverse', 'hidden', 'dim',
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
class CoolBar:
|
|
20
|
+
def __init__(self, total, width=40, color:COLORS='intense_green', fill='█', empty='░', prefix='', suffix='', start=0, done_msg='', under_msg='', over_msg='', spinner_func=None, spinner_max_frames=None, unit='it'):
|
|
21
|
+
self.total = total
|
|
22
|
+
self.width = width
|
|
23
|
+
self.color = color
|
|
24
|
+
self.fill = fill
|
|
25
|
+
self.empty = empty
|
|
26
|
+
self.current = start
|
|
27
|
+
self.prefix = prefix
|
|
28
|
+
self.suffix = suffix
|
|
29
|
+
self.done_msg = done_msg
|
|
30
|
+
self.under_msg = under_msg
|
|
31
|
+
self.over_msg = over_msg
|
|
32
|
+
self.spinner_func = spinner_func
|
|
33
|
+
self.spinner_max_frames = spinner_max_frames
|
|
34
|
+
self.spinner_frames = -1
|
|
35
|
+
self.spinner = ''
|
|
36
|
+
self.unit = unit
|
|
37
|
+
|
|
38
|
+
self.start_time = time.time()
|
|
39
|
+
self.last_update_time = self.start_time
|
|
40
|
+
self.update_count = 0
|
|
41
|
+
self.speed = 0.0
|
|
42
|
+
self.eta = 0.0
|
|
43
|
+
|
|
44
|
+
def update(self, n=1):
|
|
45
|
+
self.current = min(self.current + n, self.total)
|
|
46
|
+
|
|
47
|
+
now = time.time()
|
|
48
|
+
elapsed = now - self.start_time
|
|
49
|
+
if elapsed > 0:
|
|
50
|
+
self.speed = self.current / elapsed
|
|
51
|
+
remaining = self.total - self.current
|
|
52
|
+
self.eta = remaining / self.speed if self.speed > 0 else 0
|
|
53
|
+
|
|
54
|
+
self._render()
|
|
55
|
+
|
|
56
|
+
def _format_time(seconds):
|
|
57
|
+
if seconds < 60:
|
|
58
|
+
return f"{seconds:.0f}s"
|
|
59
|
+
elif seconds < 3600:
|
|
60
|
+
return f"{seconds/60:.0f}m {seconds%60:.0f}s"
|
|
61
|
+
else:
|
|
62
|
+
return f"{seconds/3600:.1f}h"
|
|
63
|
+
|
|
64
|
+
def _render(self):
|
|
65
|
+
if self.spinner_func is not None:
|
|
66
|
+
self.spinner_frames += 1
|
|
67
|
+
if self.spinner_max_frames is not None:
|
|
68
|
+
self.spinner_frames = self.spinner_frames % self.spinner_max_frames
|
|
69
|
+
self.spinner = self.spinner_func(self.spinner_frames)
|
|
70
|
+
if self.total == 0:
|
|
71
|
+
percent = 100.0
|
|
72
|
+
filled = self.width
|
|
73
|
+
else:
|
|
74
|
+
percent = self.current / self.total * 100
|
|
75
|
+
filled = int(self.width * self.current / self.total)
|
|
76
|
+
bar = self.fill * filled + self.empty * (self.width - filled)
|
|
77
|
+
if self.current > self.total:
|
|
78
|
+
bar = f'{self.current}{self.unit}'
|
|
79
|
+
colored_bar = nc.style(bar, self.color)
|
|
80
|
+
speed_str = f"{self.speed:.1f} {self.unit}/s"
|
|
81
|
+
eta_str = self._format_time(self.eta) if self.eta > 0 else "∞"
|
|
82
|
+
line = f"\r{self.prefix}: {colored_bar} {percent:3.0f}% | {self.spinner} {self.suffix} | {speed_str} | ETA: {eta_str}"
|
|
83
|
+
cols = get_terminal_size().columns
|
|
84
|
+
line = line.ljust(cols)
|
|
85
|
+
|
|
86
|
+
stdout.write(line)
|
|
87
|
+
stdout.flush()
|
|
88
|
+
|
|
89
|
+
def _finish(self):
|
|
90
|
+
if self.current == self.total:
|
|
91
|
+
print(f'{self.done_msg}')
|
|
92
|
+
elif self.current > self.total:
|
|
93
|
+
print(f'{self.over_msg}')
|
|
94
|
+
else:
|
|
95
|
+
print(f'{self.under_msg}')
|
|
96
|
+
|
|
97
|
+
def __enter__(self):
|
|
98
|
+
return self
|
|
99
|
+
|
|
100
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
101
|
+
self._finish()
|
|
102
|
+
|
|
103
|
+
def __call__(self, n=1):
|
|
104
|
+
self.update(n)
|
|
105
|
+
|
|
106
|
+
def __iter__(self):
|
|
107
|
+
self.current = 0
|
|
108
|
+
self._render()
|
|
109
|
+
return self
|
|
110
|
+
|
|
111
|
+
def __next__(self):
|
|
112
|
+
if self.current >= self.total:
|
|
113
|
+
raise StopIteration
|
|
114
|
+
self.update(1)
|
|
115
|
+
return self.current
|
|
116
|
+
|
|
117
|
+
__all__ = ['CoolBar', 'COLORS']
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pycoolprogressbar
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Progress bars with cool ANSI styling! and more!
|
|
5
|
+
Author: robert-ish
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/robert-ish/coolbar
|
|
8
|
+
Project-URL: Repository, https://github.com/robert-ish/coolbar
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: yet-another-ansi-lib>=0.1.1
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# coolbar
|
|
18
|
+
Aims to be the ultimate progress bar package for python.
|
|
19
|
+
(But i dont believe in myself so it fails)
|
|
20
|
+
## Installation
|
|
21
|
+
```bash
|
|
22
|
+
pip install pycoolprogressbar
|
|
23
|
+
```
|
|
24
|
+
## Usage
|
|
25
|
+
```python
|
|
26
|
+
from pycoolprogressbar import CoolBar
|
|
27
|
+
import time
|
|
28
|
+
for i in CoolBar(100):
|
|
29
|
+
time.sleep(0.02)
|
|
30
|
+
```
|
|
31
|
+
## CoolBar class
|
|
32
|
+
This is the main class for everything
|
|
33
|
+
It can be used as an iterable or as a context manager
|
|
34
|
+
### __init__ (creating the instance):
|
|
35
|
+
This can be kinda confusing?
|
|
36
|
+
args:
|
|
37
|
+
total: the maximum value of the progress bar. Can be overshot.
|
|
38
|
+
width: the length of the progress bar, in characters.
|
|
39
|
+
color: must be a color from the COLORS_LIST
|
|
40
|
+
fill: changes the character displayed for filled segments.
|
|
41
|
+
empty: changes the character displayed for unfilled segments.
|
|
42
|
+
prefix: displayed in the bar before the bar. use as a title (eg.: "Loading")
|
|
43
|
+
suffix: displayed after the bar but before everything else, surprisingly. Could use to describe what you're doing
|
|
44
|
+
start: what value the bar starts from.
|
|
45
|
+
done_msg: printed when bar ends with no errors
|
|
46
|
+
under_msg: printed when the bar ends without reaching total.
|
|
47
|
+
over_msg: printed when the bar ends with current being more than total.
|
|
48
|
+
spinner_func: used to add a spinner to the bar. It should be a function, and you should preferably add limiting frames yourself
|
|
49
|
+
spinner_max_frames: additional frame limit. it should be how much frames you have - 1
|
|
50
|
+
unit: what is displayed when overshot and in the speed counter.
|
|
51
|
+
### CoolBar.update(n)
|
|
52
|
+
Adds n to the instances current count.
|
|
53
|
+
This is also called when calling the coolbar class itself
|
|
54
|
+
Can overshoot total.
|
|
55
|
+
## License
|
|
56
|
+
MIT
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
pycoolprogressbar/__init__.py,sha256=BslA54l70KSU6a0-Rae6y6Y6EXmKu4jdI-wH1wawPQU,4179
|
|
2
|
+
pycoolprogressbar-0.1.0.dist-info/licenses/LICENSE,sha256=4hEXM7QJl6WNEeOeGvDsIsm7de04VXhKjs1l756Wcvw,1086
|
|
3
|
+
pycoolprogressbar-0.1.0.dist-info/METADATA,sha256=ArhTO7qMdipbJtIzZ_pI6ut8_Orv9mqv6I_h0mqHGt8,2181
|
|
4
|
+
pycoolprogressbar-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
5
|
+
pycoolprogressbar-0.1.0.dist-info/top_level.txt,sha256=qBi_cdCIpRKv_N-J7MFYdpJLfNeSwfH20saicOF8byg,18
|
|
6
|
+
pycoolprogressbar-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 robert-ish
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pycoolprogressbar
|