textfmt 0.1.0__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.
- {textfmt-0.1.0.dist-info → textfmt-0.2.0.dist-info}/METADATA +17 -14
- textfmt-0.2.0.dist-info/RECORD +10 -0
- {textfmt-0.1.0.dist-info → textfmt-0.2.0.dist-info}/WHEEL +1 -1
- textfmt-0.2.0.dist-info/licenses/LICENSE +21 -0
- textformat/__init__.py +2 -3
- textformat/progress.py +86 -0
- textformat/textformat.py +12 -0
- textfmt-0.1.0.dist-info/RECORD +0 -8
- {textfmt-0.1.0.dist-info → textfmt-0.2.0.dist-info}/top_level.txt +0 -0
@@ -1,16 +1,18 @@
|
|
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
|
8
8
|
Requires-Python: >=3.6
|
9
9
|
Description-Content-Type: text/markdown
|
10
|
+
License-File: LICENSE
|
11
|
+
Dynamic: license-file
|
10
12
|
|
11
|
-
#
|
13
|
+
# TextFormat
|
12
14
|
|
13
|
-
|
15
|
+
TextFormat is a lightweight Python module for ANSI text formatting, customizable word art, and table rendering in CLI applications.
|
14
16
|
|
15
17
|
## Features
|
16
18
|
- **ANSI Colors & Styles** – Easily format text using intuitive color mappings.
|
@@ -20,38 +22,39 @@ A lightweight Python module for ANSI text formatting, customizable word art, and
|
|
20
22
|
## Installation
|
21
23
|
Install via PyPI:
|
22
24
|
```sh
|
23
|
-
pip install
|
25
|
+
pip install textfmt
|
24
26
|
```
|
25
27
|
|
26
28
|
## Usage
|
27
|
-
|
28
29
|
Basic Text Formatting
|
29
|
-
|
30
30
|
```python
|
31
|
-
import
|
31
|
+
from textformat import TextFormat
|
32
32
|
|
33
|
-
print(
|
33
|
+
print(TextFormat.style("Hello, World!", TextFormat.BOLD, TextFormat.COLORS["blue"]))
|
34
34
|
```
|
35
35
|
|
36
36
|
Custom Word Art Banner
|
37
|
+
|
37
38
|
```python
|
38
|
-
|
39
|
+
from textformat.word_art import WordArt
|
39
40
|
|
40
|
-
print(
|
41
|
+
print(WordArt.banner("TEXTFORMAT", char="*", width=40))
|
41
42
|
```
|
42
43
|
|
43
44
|
Table Rendering
|
44
45
|
```python
|
45
|
-
|
46
|
+
from textformat.table import TableFormatter
|
46
47
|
|
47
|
-
headers = ["
|
48
|
+
headers = ["Feature", "Color", "Effect"]
|
48
49
|
data = [
|
49
50
|
["Bold", "White", "Strong emphasis"],
|
50
51
|
["Underline", "Blue", "Text decoration"],
|
51
52
|
["Warning", "Yellow", "Cautionary message"],
|
52
53
|
]
|
53
54
|
|
54
|
-
print(
|
55
|
+
print(TableFormatter.generate(headers, data))
|
55
56
|
```
|
57
|
+
|
56
58
|
## License
|
59
|
+
|
57
60
|
MIT License – Free to use and modify.
|
@@ -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,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Rihaan Meher
|
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.
|
textformat/__init__.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# textfmt/__init__.py
|
2
|
-
from .textformat import TextFormat
|
2
|
+
from .textformat import TextFormat, bcolors
|
3
3
|
from .word_art import WordArt
|
4
4
|
from .table import TableFormatter
|
5
|
-
|
6
|
-
__all__ = ["TextFormat", "WordArt", "TableFormatter"]
|
5
|
+
__all__ = ["TextFormat", "bcolors", "WordArt", "TableFormatter"]
|
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
|
+
|
textformat/textformat.py
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
class bcolors:
|
2
|
+
HEADER = '\033[95m'
|
3
|
+
OKBLUE = '\033[94m'
|
4
|
+
OKCYAN = '\033[96m'
|
5
|
+
OKGREEN = '\033[92m'
|
6
|
+
NOTE = '\x1b[35m'
|
7
|
+
WARNING = '\033[93m'
|
8
|
+
FAIL = '\033[91m'
|
9
|
+
ENDC = '\033[0m'
|
10
|
+
BOLD = '\033[1m'
|
11
|
+
UNDERLINE = '\033[4m'
|
12
|
+
|
1
13
|
class TextFormat:
|
2
14
|
""" ANSI Escape Code Formatting for Python CLI Output """
|
3
15
|
RESET = "\x1b[0m"
|
textfmt-0.1.0.dist-info/RECORD
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
textformat/__init__.py,sha256=OeDcG1aKyzES1aLCdjxC06NYtNBDRMrqnGVO7KDW1pc,182
|
2
|
-
textformat/table.py,sha256=GA7MsMWNuug61XxK9Ot3SOg5bl9zh5GO9Hae8-Y2qeE,604
|
3
|
-
textformat/textformat.py,sha256=hRfVOZqQCT8955F9qj8_rFPPn0tZxtOpogRtkxZ7BL8,859
|
4
|
-
textformat/word_art.py,sha256=GsJka0ukV23FTvhuyuGRChhNGOjTWOdKBK3h0e-LnX8,318
|
5
|
-
textfmt-0.1.0.dist-info/METADATA,sha256=ojispDnWgHDPog7otaNGULpybth0GFLuFUM2qKRW7Hw,1486
|
6
|
-
textfmt-0.1.0.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
7
|
-
textfmt-0.1.0.dist-info/top_level.txt,sha256=Nf6G1sI6EqA2opfIdIio6ZqKNbpT2EtYf5cd0sKgPRo,11
|
8
|
-
textfmt-0.1.0.dist-info/RECORD,,
|
File without changes
|