baraloda 0.1.0__tar.gz

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,132 @@
1
+ Metadata-Version: 2.4
2
+ Name: baraloda
3
+ Version: 0.1.0
4
+ Summary: A small animated loading bar for the terminal.
5
+ Author: Prankapple
6
+ License: MIT
7
+ Keywords: loading,progress,progress-bar,terminal,cli
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Environment :: Console
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: colorama>=0.4.6
15
+
16
+ # baraloda
17
+
18
+ A small animated loading bar for the terminal. It keeps running while a condition you provide is true, then finishes with a checkmark.
19
+
20
+ ## Features
21
+
22
+ - Smooth fill using eighth-block characters (`▏▎▍▌▋▊▉█`)
23
+ - Animated Braille spinner and live elapsed-time counter
24
+ - Custom color (a string like `"green"` or a `colorama` `Fore` constant)
25
+ - Hides the cursor while running and always restores it
26
+ - Clean Ctrl+C handling (prints "cancelled" instead of a traceback)
27
+ - Works on Windows, macOS and Linux
28
+
29
+ ## Installation
30
+
31
+ From the project folder:
32
+
33
+ ```bash
34
+ pip install baraloda
35
+ ```
36
+
37
+ Requires Python 3.8+ and [colorama](https://pypi.org/project/colorama/), which is installed automatically.
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ import time
43
+ from baraloda import NewLoadingBar
44
+
45
+ end = time.time() + 5
46
+ NewLoadingBar(30, "cyan", lambda: time.time() < end, speed=0.08, prefix="Working")
47
+ ```
48
+
49
+ The longer import also works:
50
+
51
+ ```python
52
+ from baraloda.loadingBar import NewLoadingBar
53
+ ```
54
+
55
+ ### With a background task
56
+
57
+ `NewLoadingBar` blocks until `func()` returns a falsey value, so run your work in a thread and flip a flag when it finishes:
58
+
59
+ ```python
60
+ import threading
61
+ import time
62
+ from baraloda import NewLoadingBar
63
+
64
+ done = threading.Event()
65
+
66
+ def work():
67
+ time.sleep(4) # your real work here
68
+ done.set()
69
+
70
+ threading.Thread(target=work, daemon=True).start()
71
+ NewLoadingBar(30, "green", lambda: not done.is_set(), prefix="Processing")
72
+ ```
73
+
74
+ ### Example: PyTorch training
75
+
76
+ ```python
77
+ import threading, time
78
+ import torch
79
+ from baraloda import NewLoadingBar
80
+
81
+ X = torch.randn(200, 2)
82
+ y = 3 * X[:, :1] - 2 * X[:, 1:]
83
+ model = torch.nn.Linear(2, 1)
84
+ opt = torch.optim.Adam(model.parameters(), lr=0.1)
85
+ done = threading.Event()
86
+
87
+ def train():
88
+ for _ in range(100):
89
+ opt.zero_grad()
90
+ loss = torch.nn.functional.mse_loss(model(X), y)
91
+ loss.backward()
92
+ opt.step()
93
+ done.set()
94
+
95
+ threading.Thread(target=train, daemon=True).start()
96
+ NewLoadingBar(30, "cyan", lambda: not done.is_set(), prefix="Training")
97
+ ```
98
+
99
+ ## API
100
+
101
+ ```python
102
+ NewLoadingBar(length, color, func, speed=0.1, prefix="Loading", steps_per_cell=4)
103
+ ```
104
+
105
+ | Parameter | Description |
106
+ | ---------------- | ---------------------------------------------------------------------- |
107
+ | `length` | Width of the bar in characters. |
108
+ | `color` | Color name (`"green"`) or a `colorama` `Fore` constant (`Fore.GREEN`). |
109
+ | `func` | Callable. The bar keeps animating while it returns a truthy value. |
110
+ | `speed` | Seconds for one cell to fill. Smaller is faster. |
111
+ | `prefix` | Label shown before the bar. |
112
+ | `steps_per_cell` | Animation smoothness. Higher values give finer steps. |
113
+
114
+ ## Notes
115
+
116
+ - `func` is checked on every animation step, so keep it cheap and non-blocking.
117
+ - Unknown color names fall back to white.
118
+
119
+ ## Project layout
120
+
121
+ ```
122
+ baraloda/
123
+ ├── baraloda/
124
+ │ ├── __init__.py
125
+ │ └── loadingBar.py
126
+ ├── pyproject.toml
127
+ └── README.md
128
+ ```
129
+
130
+ ## License
131
+
132
+ MIT
@@ -0,0 +1,117 @@
1
+ # baraloda
2
+
3
+ A small animated loading bar for the terminal. It keeps running while a condition you provide is true, then finishes with a checkmark.
4
+
5
+ ## Features
6
+
7
+ - Smooth fill using eighth-block characters (`▏▎▍▌▋▊▉█`)
8
+ - Animated Braille spinner and live elapsed-time counter
9
+ - Custom color (a string like `"green"` or a `colorama` `Fore` constant)
10
+ - Hides the cursor while running and always restores it
11
+ - Clean Ctrl+C handling (prints "cancelled" instead of a traceback)
12
+ - Works on Windows, macOS and Linux
13
+
14
+ ## Installation
15
+
16
+ From the project folder:
17
+
18
+ ```bash
19
+ pip install baraloda
20
+ ```
21
+
22
+ Requires Python 3.8+ and [colorama](https://pypi.org/project/colorama/), which is installed automatically.
23
+
24
+ ## Usage
25
+
26
+ ```python
27
+ import time
28
+ from baraloda import NewLoadingBar
29
+
30
+ end = time.time() + 5
31
+ NewLoadingBar(30, "cyan", lambda: time.time() < end, speed=0.08, prefix="Working")
32
+ ```
33
+
34
+ The longer import also works:
35
+
36
+ ```python
37
+ from baraloda.loadingBar import NewLoadingBar
38
+ ```
39
+
40
+ ### With a background task
41
+
42
+ `NewLoadingBar` blocks until `func()` returns a falsey value, so run your work in a thread and flip a flag when it finishes:
43
+
44
+ ```python
45
+ import threading
46
+ import time
47
+ from baraloda import NewLoadingBar
48
+
49
+ done = threading.Event()
50
+
51
+ def work():
52
+ time.sleep(4) # your real work here
53
+ done.set()
54
+
55
+ threading.Thread(target=work, daemon=True).start()
56
+ NewLoadingBar(30, "green", lambda: not done.is_set(), prefix="Processing")
57
+ ```
58
+
59
+ ### Example: PyTorch training
60
+
61
+ ```python
62
+ import threading, time
63
+ import torch
64
+ from baraloda import NewLoadingBar
65
+
66
+ X = torch.randn(200, 2)
67
+ y = 3 * X[:, :1] - 2 * X[:, 1:]
68
+ model = torch.nn.Linear(2, 1)
69
+ opt = torch.optim.Adam(model.parameters(), lr=0.1)
70
+ done = threading.Event()
71
+
72
+ def train():
73
+ for _ in range(100):
74
+ opt.zero_grad()
75
+ loss = torch.nn.functional.mse_loss(model(X), y)
76
+ loss.backward()
77
+ opt.step()
78
+ done.set()
79
+
80
+ threading.Thread(target=train, daemon=True).start()
81
+ NewLoadingBar(30, "cyan", lambda: not done.is_set(), prefix="Training")
82
+ ```
83
+
84
+ ## API
85
+
86
+ ```python
87
+ NewLoadingBar(length, color, func, speed=0.1, prefix="Loading", steps_per_cell=4)
88
+ ```
89
+
90
+ | Parameter | Description |
91
+ | ---------------- | ---------------------------------------------------------------------- |
92
+ | `length` | Width of the bar in characters. |
93
+ | `color` | Color name (`"green"`) or a `colorama` `Fore` constant (`Fore.GREEN`). |
94
+ | `func` | Callable. The bar keeps animating while it returns a truthy value. |
95
+ | `speed` | Seconds for one cell to fill. Smaller is faster. |
96
+ | `prefix` | Label shown before the bar. |
97
+ | `steps_per_cell` | Animation smoothness. Higher values give finer steps. |
98
+
99
+ ## Notes
100
+
101
+ - `func` is checked on every animation step, so keep it cheap and non-blocking.
102
+ - Unknown color names fall back to white.
103
+
104
+ ## Project layout
105
+
106
+ ```
107
+ baraloda/
108
+ ├── baraloda/
109
+ │ ├── __init__.py
110
+ │ └── loadingBar.py
111
+ ├── pyproject.toml
112
+ └── README.md
113
+ ```
114
+
115
+ ## License
116
+
117
+ MIT
@@ -0,0 +1,6 @@
1
+ """baraloda - a small animated terminal loading bar."""
2
+
3
+ from .loadingBar import NewLoadingBar
4
+
5
+ __all__ = ["NewLoadingBar"]
6
+ __version__ = "0.1.0"
@@ -0,0 +1,83 @@
1
+ import sys
2
+ import time
3
+ from colorama import Fore, Style, just_fix_windows_console
4
+
5
+ just_fix_windows_console()
6
+
7
+ SPINNER = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
8
+ PARTIAL = " ▏▎▍▌▋▊▉" # eighth-block steps for smooth fill
9
+ HIDE_CURSOR = "\033[?25l"
10
+ SHOW_CURSOR = "\033[?25h"
11
+ CLEAR_LINE = "\033[2K"
12
+
13
+
14
+ def _resolve_color(color):
15
+ """Accepts a string ("green") or a Fore constant (Fore.GREEN)."""
16
+ if isinstance(color, str):
17
+ return getattr(Fore, color.upper(), Fore.WHITE)
18
+ return color
19
+
20
+
21
+ def _render_bar(fraction, length):
22
+ """Build a smooth bar (sub-character precision) of `length` cells."""
23
+ total_eighths = int(fraction * length * 8)
24
+ full, rem = divmod(total_eighths, 8)
25
+ full = min(full, length)
26
+ bar = "█" * full
27
+ if full < length:
28
+ bar += PARTIAL[rem]
29
+ bar += " " * (length - full - 1)
30
+ return bar
31
+
32
+
33
+ def NewLoadingBar(length, color, func, speed=0.1, prefix="Loading", steps_per_cell=4):
34
+ """
35
+ Animated loading bar that keeps looping while func() returns True.
36
+
37
+ length - width of the bar in characters
38
+ color - "green" or Fore.GREEN
39
+ func - callable; bar runs while it returns truthy
40
+ speed - seconds for one cell to fill (smaller = faster)
41
+ prefix - label shown before the bar
42
+ steps_per_cell - animation smoothness (higher = smoother)
43
+ """
44
+ bar_color = _resolve_color(color)
45
+ dim = Style.DIM
46
+ reset = Style.RESET_ALL
47
+ total_steps = length * steps_per_cell
48
+ delay = speed / steps_per_cell
49
+ start = time.time()
50
+ frame = 0
51
+
52
+ def draw(fraction, spinner=True, done=False):
53
+ percent = int(fraction * 100)
54
+ elapsed = time.time() - start
55
+ icon = (
56
+ f"{bar_color}✔{reset}"
57
+ if done
58
+ else f"{bar_color}{SPINNER[frame % len(SPINNER)]}{reset}"
59
+ )
60
+ bar = _render_bar(fraction, length)
61
+ sys.stdout.write(
62
+ f"\r{CLEAR_LINE}{icon} {Style.BRIGHT}{prefix}{reset} "
63
+ f"{dim}▕{reset}{bar_color}{bar}{reset}{dim}▏{reset} "
64
+ f"{Style.BRIGHT}{percent:>3}%{reset} {dim}{elapsed:5.1f}s{reset}"
65
+ )
66
+ sys.stdout.flush()
67
+
68
+ sys.stdout.write(HIDE_CURSOR)
69
+ try:
70
+ while func():
71
+ for step in range(total_steps + 1):
72
+ if not func():
73
+ break
74
+ draw(step / total_steps)
75
+ frame += 1
76
+ time.sleep(delay)
77
+ draw(1.0, done=True)
78
+ sys.stdout.write("\n")
79
+ except KeyboardInterrupt:
80
+ sys.stdout.write(f"\r{CLEAR_LINE}{Fore.YELLOW}✖ {prefix} cancelled{reset}\n")
81
+ finally:
82
+ sys.stdout.write(SHOW_CURSOR)
83
+ sys.stdout.flush()
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.4
2
+ Name: baraloda
3
+ Version: 0.1.0
4
+ Summary: A small animated loading bar for the terminal.
5
+ Author: Prankapple
6
+ License: MIT
7
+ Keywords: loading,progress,progress-bar,terminal,cli
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Environment :: Console
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: colorama>=0.4.6
15
+
16
+ # baraloda
17
+
18
+ A small animated loading bar for the terminal. It keeps running while a condition you provide is true, then finishes with a checkmark.
19
+
20
+ ## Features
21
+
22
+ - Smooth fill using eighth-block characters (`▏▎▍▌▋▊▉█`)
23
+ - Animated Braille spinner and live elapsed-time counter
24
+ - Custom color (a string like `"green"` or a `colorama` `Fore` constant)
25
+ - Hides the cursor while running and always restores it
26
+ - Clean Ctrl+C handling (prints "cancelled" instead of a traceback)
27
+ - Works on Windows, macOS and Linux
28
+
29
+ ## Installation
30
+
31
+ From the project folder:
32
+
33
+ ```bash
34
+ pip install baraloda
35
+ ```
36
+
37
+ Requires Python 3.8+ and [colorama](https://pypi.org/project/colorama/), which is installed automatically.
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ import time
43
+ from baraloda import NewLoadingBar
44
+
45
+ end = time.time() + 5
46
+ NewLoadingBar(30, "cyan", lambda: time.time() < end, speed=0.08, prefix="Working")
47
+ ```
48
+
49
+ The longer import also works:
50
+
51
+ ```python
52
+ from baraloda.loadingBar import NewLoadingBar
53
+ ```
54
+
55
+ ### With a background task
56
+
57
+ `NewLoadingBar` blocks until `func()` returns a falsey value, so run your work in a thread and flip a flag when it finishes:
58
+
59
+ ```python
60
+ import threading
61
+ import time
62
+ from baraloda import NewLoadingBar
63
+
64
+ done = threading.Event()
65
+
66
+ def work():
67
+ time.sleep(4) # your real work here
68
+ done.set()
69
+
70
+ threading.Thread(target=work, daemon=True).start()
71
+ NewLoadingBar(30, "green", lambda: not done.is_set(), prefix="Processing")
72
+ ```
73
+
74
+ ### Example: PyTorch training
75
+
76
+ ```python
77
+ import threading, time
78
+ import torch
79
+ from baraloda import NewLoadingBar
80
+
81
+ X = torch.randn(200, 2)
82
+ y = 3 * X[:, :1] - 2 * X[:, 1:]
83
+ model = torch.nn.Linear(2, 1)
84
+ opt = torch.optim.Adam(model.parameters(), lr=0.1)
85
+ done = threading.Event()
86
+
87
+ def train():
88
+ for _ in range(100):
89
+ opt.zero_grad()
90
+ loss = torch.nn.functional.mse_loss(model(X), y)
91
+ loss.backward()
92
+ opt.step()
93
+ done.set()
94
+
95
+ threading.Thread(target=train, daemon=True).start()
96
+ NewLoadingBar(30, "cyan", lambda: not done.is_set(), prefix="Training")
97
+ ```
98
+
99
+ ## API
100
+
101
+ ```python
102
+ NewLoadingBar(length, color, func, speed=0.1, prefix="Loading", steps_per_cell=4)
103
+ ```
104
+
105
+ | Parameter | Description |
106
+ | ---------------- | ---------------------------------------------------------------------- |
107
+ | `length` | Width of the bar in characters. |
108
+ | `color` | Color name (`"green"`) or a `colorama` `Fore` constant (`Fore.GREEN`). |
109
+ | `func` | Callable. The bar keeps animating while it returns a truthy value. |
110
+ | `speed` | Seconds for one cell to fill. Smaller is faster. |
111
+ | `prefix` | Label shown before the bar. |
112
+ | `steps_per_cell` | Animation smoothness. Higher values give finer steps. |
113
+
114
+ ## Notes
115
+
116
+ - `func` is checked on every animation step, so keep it cheap and non-blocking.
117
+ - Unknown color names fall back to white.
118
+
119
+ ## Project layout
120
+
121
+ ```
122
+ baraloda/
123
+ ├── baraloda/
124
+ │ ├── __init__.py
125
+ │ └── loadingBar.py
126
+ ├── pyproject.toml
127
+ └── README.md
128
+ ```
129
+
130
+ ## License
131
+
132
+ MIT
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ baraloda/__init__.py
4
+ baraloda/loadingBar.py
5
+ baraloda.egg-info/PKG-INFO
6
+ baraloda.egg-info/SOURCES.txt
7
+ baraloda.egg-info/dependency_links.txt
8
+ baraloda.egg-info/requires.txt
9
+ baraloda.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ colorama>=0.4.6
@@ -0,0 +1 @@
1
+ baraloda
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "baraloda"
7
+ version = "0.1.0"
8
+ description = "A small animated loading bar for the terminal."
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "Prankapple" }]
13
+ keywords = ["loading", "progress", "progress-bar", "terminal", "cli"]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ "Environment :: Console",
19
+ ]
20
+ dependencies = ["colorama>=0.4.6"]
21
+
22
+ [tool.setuptools]
23
+ packages = ["baraloda"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+