myprintx 1.0.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.
- myprintx-1.0.0/LICENSE +0 -0
- myprintx-1.0.0/PKG-INFO +41 -0
- myprintx-1.0.0/README.md +15 -0
- myprintx-1.0.0/myprintx/__init__.py +4 -0
- myprintx-1.0.0/myprintx/core.py +106 -0
- myprintx-1.0.0/myprintx.egg-info/PKG-INFO +41 -0
- myprintx-1.0.0/myprintx.egg-info/SOURCES.txt +9 -0
- myprintx-1.0.0/myprintx.egg-info/dependency_links.txt +1 -0
- myprintx-1.0.0/myprintx.egg-info/top_level.txt +1 -0
- myprintx-1.0.0/setup.cfg +4 -0
- myprintx-1.0.0/setup.py +21 -0
myprintx-1.0.0/LICENSE
ADDED
|
File without changes
|
myprintx-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: myprintx
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: An enhanced print function supporting color and text styles.
|
|
5
|
+
Home-page: https://github.com/1061700625/myprintx
|
|
6
|
+
Author: Hualala
|
|
7
|
+
Author-email: 1061700625@qq.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Utilities
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Requires-Python: >=3.7
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: description
|
|
20
|
+
Dynamic: description-content-type
|
|
21
|
+
Dynamic: home-page
|
|
22
|
+
Dynamic: license
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
# myprintx 🎨
|
|
28
|
+
A lightweight Python library that enhances the built-in `print()` function.
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
- ✅ Foreground & background color control
|
|
32
|
+
- ✅ Text styles: **bold**, _italic_, underline
|
|
33
|
+
- ✅ Compatible with built-in `print` behavior
|
|
34
|
+
- ✅ Optional global patch (one line activation)
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
```bash
|
|
38
|
+
pip install myprint
|
|
39
|
+
|
|
40
|
+
## TODO
|
|
41
|
+
more ...
|
myprintx-1.0.0/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# myprintx 🎨
|
|
2
|
+
A lightweight Python library that enhances the built-in `print()` function.
|
|
3
|
+
|
|
4
|
+
## Features
|
|
5
|
+
- ✅ Foreground & background color control
|
|
6
|
+
- ✅ Text styles: **bold**, _italic_, underline
|
|
7
|
+
- ✅ Compatible with built-in `print` behavior
|
|
8
|
+
- ✅ Optional global patch (one line activation)
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
```bash
|
|
12
|
+
pip install myprint
|
|
13
|
+
|
|
14
|
+
## TODO
|
|
15
|
+
more ...
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import sys, os, builtins
|
|
2
|
+
|
|
3
|
+
def print(
|
|
4
|
+
*args,
|
|
5
|
+
sep=' ',
|
|
6
|
+
end='\n',
|
|
7
|
+
file=None,
|
|
8
|
+
flush=False,
|
|
9
|
+
fg_color=None,
|
|
10
|
+
bg_color=None,
|
|
11
|
+
style=None
|
|
12
|
+
):
|
|
13
|
+
"""
|
|
14
|
+
myprintx.print() —— 彩色与样式增强版 print
|
|
15
|
+
==========================================
|
|
16
|
+
参数:
|
|
17
|
+
fg_color: 前景色 ['black','red','green','yellow','blue','purple','cyan','white']
|
|
18
|
+
bg_color: 背景色(可加 'bg_' 前缀)
|
|
19
|
+
style: 字体样式 ['bold','underline','italic']
|
|
20
|
+
示例:
|
|
21
|
+
print("成功", fg_color="green", style="bold")
|
|
22
|
+
print("错误", fg_color="white", bg_color="red")
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
# 启用 Windows 终端颜色支持
|
|
26
|
+
if sys.platform == "win32":
|
|
27
|
+
os.system("")
|
|
28
|
+
|
|
29
|
+
# ANSI 颜色映射表
|
|
30
|
+
color_map = {
|
|
31
|
+
# 前景色
|
|
32
|
+
'black': 30, 'red': 31, 'green': 32, 'yellow': 33,
|
|
33
|
+
'blue': 34, 'purple': 35, 'cyan': 36, 'white': 37,
|
|
34
|
+
# 背景色
|
|
35
|
+
'bg_black': 40, 'bg_red': 41, 'bg_green': 42, 'bg_yellow': 43,
|
|
36
|
+
'bg_blue': 44, 'bg_purple': 45, 'bg_cyan': 46, 'bg_white': 47
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# 样式映射表
|
|
40
|
+
style_map = {
|
|
41
|
+
'bold': 1,
|
|
42
|
+
'underline': 4,
|
|
43
|
+
'italic': 3
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
codes = []
|
|
47
|
+
|
|
48
|
+
# 添加样式控制码
|
|
49
|
+
if style and style in style_map:
|
|
50
|
+
codes.append(str(style_map[style]))
|
|
51
|
+
|
|
52
|
+
# 添加前景色控制码
|
|
53
|
+
if fg_color:
|
|
54
|
+
if fg_color in color_map:
|
|
55
|
+
codes.append(str(color_map[fg_color]))
|
|
56
|
+
elif f"fg_{fg_color}" in color_map:
|
|
57
|
+
codes.append(str(color_map[f"fg_{fg_color}"]))
|
|
58
|
+
|
|
59
|
+
# 添加背景色控制码
|
|
60
|
+
if bg_color:
|
|
61
|
+
bg_key = bg_color if bg_color.startswith("bg_") else f"bg_{bg_color}"
|
|
62
|
+
if bg_key in color_map:
|
|
63
|
+
codes.append(str(color_map[bg_key]))
|
|
64
|
+
|
|
65
|
+
prefix = f"\033[{';'.join(codes)}m" if codes else ''
|
|
66
|
+
suffix = "\033[0m" if codes else ''
|
|
67
|
+
|
|
68
|
+
text = sep.join(map(str, args))
|
|
69
|
+
output = f"{prefix}{text}{suffix}"
|
|
70
|
+
|
|
71
|
+
# 安全调用原始 print(避免递归,同时兼容未打补丁的情况)
|
|
72
|
+
if hasattr(builtins, "__orig_print__"):
|
|
73
|
+
builtins.__orig_print__(output, sep=sep, end=end, file=file or sys.stdout, flush=flush)
|
|
74
|
+
else:
|
|
75
|
+
builtins.print(output, sep=sep, end=end, file=file or sys.stdout, flush=flush)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def patch_color():
|
|
80
|
+
"""
|
|
81
|
+
自动为全局 print() 启用彩色增强功能
|
|
82
|
+
-------------------------------------
|
|
83
|
+
调用后,系统内所有 print() 均支持:
|
|
84
|
+
fg_color / bg_color / style 参数。
|
|
85
|
+
|
|
86
|
+
示例:
|
|
87
|
+
>>> import myprintx
|
|
88
|
+
>>> myprintx.auto_patch_color()
|
|
89
|
+
>>> print("绿色文字", fg_color="green", style="bold")
|
|
90
|
+
|
|
91
|
+
可随时通过 myprintx.unpatch() 恢复原始 print。
|
|
92
|
+
"""
|
|
93
|
+
if not hasattr(builtins, "__orig_print__"):
|
|
94
|
+
builtins.__orig_print__ = builtins.print
|
|
95
|
+
builtins.print = print
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def unpatch_color():
|
|
99
|
+
"""
|
|
100
|
+
恢复原始 print()(撤销所有增强)
|
|
101
|
+
--------------------------------
|
|
102
|
+
若之前执行过 auto_patch_color(),可使用该函数恢复。
|
|
103
|
+
"""
|
|
104
|
+
if hasattr(builtins, "__orig_print__"):
|
|
105
|
+
builtins.print = builtins.__orig_print__
|
|
106
|
+
del builtins.__orig_print__
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: myprintx
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: An enhanced print function supporting color and text styles.
|
|
5
|
+
Home-page: https://github.com/1061700625/myprintx
|
|
6
|
+
Author: Hualala
|
|
7
|
+
Author-email: 1061700625@qq.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Utilities
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Requires-Python: >=3.7
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: description
|
|
20
|
+
Dynamic: description-content-type
|
|
21
|
+
Dynamic: home-page
|
|
22
|
+
Dynamic: license
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
# myprintx 🎨
|
|
28
|
+
A lightweight Python library that enhances the built-in `print()` function.
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
- ✅ Foreground & background color control
|
|
32
|
+
- ✅ Text styles: **bold**, _italic_, underline
|
|
33
|
+
- ✅ Compatible with built-in `print` behavior
|
|
34
|
+
- ✅ Optional global patch (one line activation)
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
```bash
|
|
38
|
+
pip install myprint
|
|
39
|
+
|
|
40
|
+
## TODO
|
|
41
|
+
more ...
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
myprintx
|
myprintx-1.0.0/setup.cfg
ADDED
myprintx-1.0.0/setup.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="myprintx",
|
|
5
|
+
version="1.0.0",
|
|
6
|
+
author="Hualala",
|
|
7
|
+
author_email="1061700625@qq.com",
|
|
8
|
+
description="An enhanced print function supporting color and text styles.",
|
|
9
|
+
long_description=open("README.md", "r", encoding="utf-8").read(),
|
|
10
|
+
long_description_content_type="text/markdown",
|
|
11
|
+
url="https://github.com/1061700625/myprintx",
|
|
12
|
+
packages=find_packages(),
|
|
13
|
+
python_requires=">=3.7",
|
|
14
|
+
license="MIT",
|
|
15
|
+
classifiers=[
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Topic :: Utilities",
|
|
19
|
+
"Intended Audience :: Developers"
|
|
20
|
+
],
|
|
21
|
+
)
|