textfmt 0.1.1__py3-none-any.whl → 0.2.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.
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: textfmt
3
- Version: 0.1.1
4
- Summary: A Python module for ANSI text formatting, word art, and table styling
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,10 @@
1
+ textfmt-0.2.0.dist-info/licenses/LICENSE,sha256=Msmy46KiAR2wmzeCe3kSl-wEt7ptbTZOAzdwUUyFq_M,1090
2
+ textformat/__init__.py,sha256=fyib7AnpkuEZ_PAzx6AO5SVKNTB5kyqk5NnJBXx7TYw,200
3
+ textformat/progress.py,sha256=9s0pndMjZ-S5dgcTZuibgAoB-oKeAAWvsjHqxij3Rtw,3253
4
+ textformat/table.py,sha256=GA7MsMWNuug61XxK9Ot3SOg5bl9zh5GO9Hae8-Y2qeE,604
5
+ textformat/textformat.py,sha256=yz6KstoDtrIgoA_b4ZFJAY9EfcylSjeeJ_euhPf8cpw,1121
6
+ textformat/word_art.py,sha256=GsJka0ukV23FTvhuyuGRChhNGOjTWOdKBK3h0e-LnX8,318
7
+ textfmt-0.2.0.dist-info/METADATA,sha256=TABcMirGCQYbNUoj0bp6jViVQKbAUQl0zjyE9UxcxmU,1567
8
+ textfmt-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ textfmt-0.2.0.dist-info/top_level.txt,sha256=Nf6G1sI6EqA2opfIdIio6ZqKNbpT2EtYf5cd0sKgPRo,11
10
+ textfmt-0.2.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.8.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
textformat/progress.py ADDED
@@ -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
+
@@ -1,9 +0,0 @@
1
- textfmt-0.1.1.dist-info/licenses/LICENSE,sha256=Msmy46KiAR2wmzeCe3kSl-wEt7ptbTZOAzdwUUyFq_M,1090
2
- textformat/__init__.py,sha256=fyib7AnpkuEZ_PAzx6AO5SVKNTB5kyqk5NnJBXx7TYw,200
3
- textformat/table.py,sha256=GA7MsMWNuug61XxK9Ot3SOg5bl9zh5GO9Hae8-Y2qeE,604
4
- textformat/textformat.py,sha256=yz6KstoDtrIgoA_b4ZFJAY9EfcylSjeeJ_euhPf8cpw,1121
5
- textformat/word_art.py,sha256=GsJka0ukV23FTvhuyuGRChhNGOjTWOdKBK3h0e-LnX8,318
6
- textfmt-0.1.1.dist-info/METADATA,sha256=HC4hKXmxtK8eHMssLwSxVQHgrrXg6ouOhIJpcs7iKAg,1566
7
- textfmt-0.1.1.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
8
- textfmt-0.1.1.dist-info/top_level.txt,sha256=Nf6G1sI6EqA2opfIdIio6ZqKNbpT2EtYf5cd0sKgPRo,11
9
- textfmt-0.1.1.dist-info/RECORD,,