textfmt 0.1.1__tar.gz → 0.2.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.
- {textfmt-0.1.1 → textfmt-0.2.0}/PKG-INFO +2 -2
- {textfmt-0.1.1 → textfmt-0.2.0}/pyproject.toml +2 -2
- {textfmt-0.1.1 → textfmt-0.2.0}/textfmt.egg-info/PKG-INFO +2 -2
- {textfmt-0.1.1 → textfmt-0.2.0}/textfmt.egg-info/SOURCES.txt +1 -0
- textfmt-0.2.0/textformat/progress.py +86 -0
- {textfmt-0.1.1 → textfmt-0.2.0}/LICENSE +0 -0
- {textfmt-0.1.1 → textfmt-0.2.0}/README.md +0 -0
- {textfmt-0.1.1 → textfmt-0.2.0}/setup.cfg +0 -0
- {textfmt-0.1.1 → textfmt-0.2.0}/textfmt.egg-info/dependency_links.txt +0 -0
- {textfmt-0.1.1 → textfmt-0.2.0}/textfmt.egg-info/top_level.txt +0 -0
- {textfmt-0.1.1 → textfmt-0.2.0}/textformat/__init__.py +0 -0
- {textfmt-0.1.1 → textfmt-0.2.0}/textformat/table.py +0 -0
- {textfmt-0.1.1 → textfmt-0.2.0}/textformat/textformat.py +0 -0
- {textfmt-0.1.1 → textfmt-0.2.0}/textformat/word_art.py +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: textfmt
|
3
|
-
Version: 0.
|
4
|
-
Summary: A Python module for
|
3
|
+
Version: 0.2.0
|
4
|
+
Summary: A Python module for terminal text styling without the overhead of rich
|
5
5
|
Author-email: Rihaan Meher <meherrihaan@gmail.com>
|
6
6
|
License: MIT
|
7
7
|
Project-URL: Homepage, https://github.com/sharktide/textformat
|
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "textfmt"
|
7
|
-
version = "0.
|
8
|
-
description = "A Python module for
|
7
|
+
version = "0.2.0"
|
8
|
+
description = "A Python module for terminal text styling without the overhead of rich"
|
9
9
|
authors = [{name = "Rihaan Meher", email = "meherrihaan@gmail.com"}]
|
10
10
|
license = {text = "MIT"}
|
11
11
|
readme = "README.md"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: textfmt
|
3
|
-
Version: 0.
|
4
|
-
Summary: A Python module for
|
3
|
+
Version: 0.2.0
|
4
|
+
Summary: A Python module for terminal text styling without the overhead of rich
|
5
5
|
Author-email: Rihaan Meher <meherrihaan@gmail.com>
|
6
6
|
License: MIT
|
7
7
|
Project-URL: Homepage, https://github.com/sharktide/textformat
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import requests
|
2
|
+
import time
|
3
|
+
from pathlib import Path
|
4
|
+
import sys
|
5
|
+
|
6
|
+
# Define color codes for terminal (ANSI escape codes)
|
7
|
+
class Colors:
|
8
|
+
RESET = "\033[0m"
|
9
|
+
GREEN = "\033[92m"
|
10
|
+
BLUE = "\033[94m"
|
11
|
+
RED = "\033[91m"
|
12
|
+
YELLOW = "\033[93m"
|
13
|
+
MAGENTA = "\033[95m"
|
14
|
+
CYAN = "\033[96m"
|
15
|
+
WHITE = "\033[97m"
|
16
|
+
LIGHT_GREEN = "\033[92m"
|
17
|
+
LIGHT_BLUE = "\033[94m"
|
18
|
+
LIGHT_RED = "\033[91m"
|
19
|
+
LIGHT_YELLOW = "\033[93m"
|
20
|
+
LIGHT_MAGENTA = "\033[95m"
|
21
|
+
LIGHT_CYAN = "\033[96m"
|
22
|
+
|
23
|
+
# List of all available colors for easy access
|
24
|
+
ALL_COLORS = [
|
25
|
+
GREEN, BLUE, RED, YELLOW, MAGENTA, CYAN, WHITE,
|
26
|
+
LIGHT_GREEN, LIGHT_BLUE, LIGHT_RED, LIGHT_YELLOW, LIGHT_MAGENTA, LIGHT_CYAN
|
27
|
+
]
|
28
|
+
|
29
|
+
class ProgressBar:
|
30
|
+
def __init__(self, total, prefix='', length=40, fill='━', empty=' ', print_end="\r",
|
31
|
+
download_color=Colors.GREEN, complete_color=Colors.BLUE):
|
32
|
+
"""
|
33
|
+
Initializes the progress bar.
|
34
|
+
|
35
|
+
Parameters:
|
36
|
+
total (int): Total number of bytes to download.
|
37
|
+
prefix (str): Prefix for the progress bar.
|
38
|
+
length (int): Length of the progress bar.
|
39
|
+
fill (str): Character to fill the progress bar.
|
40
|
+
empty (str): Character to represent empty space in the progress bar.
|
41
|
+
print_end (str): Ending character for printing.
|
42
|
+
download_color (str): Color code for progress bar during download.
|
43
|
+
complete_color (str): Color code for progress bar when download is complete.
|
44
|
+
"""
|
45
|
+
self.total = total
|
46
|
+
self.prefix = prefix
|
47
|
+
self.length = length
|
48
|
+
self.fill = fill
|
49
|
+
self.empty = empty
|
50
|
+
self.print_end = print_end
|
51
|
+
self.download_color = download_color
|
52
|
+
self.complete_color = complete_color
|
53
|
+
self.start_time = time.time()
|
54
|
+
self.downloaded = 0
|
55
|
+
|
56
|
+
def update(self, downloaded):
|
57
|
+
self.downloaded = downloaded
|
58
|
+
percent = ("{0:.1f}").format(100 * (self.downloaded / float(self.total)))
|
59
|
+
filled_length = int(self.length * self.downloaded // self.total)
|
60
|
+
bar = self.fill * filled_length + self.empty * (self.length - filled_length)
|
61
|
+
|
62
|
+
# Calculate current file size and total file size
|
63
|
+
current_size = self.format_size(self.downloaded)
|
64
|
+
total_size = self.format_size(self.total)
|
65
|
+
|
66
|
+
# Set color based on progress
|
67
|
+
if self.downloaded == self.total:
|
68
|
+
color = self.complete_color # Completed color
|
69
|
+
else:
|
70
|
+
color = self.download_color # Downloading color
|
71
|
+
|
72
|
+
# Print the progress bar with color, percentage, and file size
|
73
|
+
sys.stdout.write(f'\r{self.prefix} {color}{bar}{Colors.RESET} {percent}% • {current_size}/{total_size}')
|
74
|
+
sys.stdout.flush()
|
75
|
+
|
76
|
+
if self.downloaded == self.total:
|
77
|
+
sys.stdout.write(self.print_end)
|
78
|
+
sys.stdout.flush()
|
79
|
+
|
80
|
+
def format_size(self, size_in_bytes):
|
81
|
+
"""Format the size in a human-readable format (e.g., KB, MB, GB)."""
|
82
|
+
for unit in ['B', 'KiB', 'MiB', 'GiB', 'TiB']:
|
83
|
+
if size_in_bytes < 1024:
|
84
|
+
return f"{size_in_bytes:.1f} {unit}"
|
85
|
+
size_in_bytes /= 1024
|
86
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|