Luci-Code-Tools 1.1.3__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.

Potentially problematic release.


This version of Luci-Code-Tools might be problematic. Click here for more details.

Luci_code_tools.py ADDED
@@ -0,0 +1,179 @@
1
+ from sys import platform, exit
2
+ from subprocess import run
3
+ from typing import Optional
4
+
5
+ __version__ = "1.0.2"
6
+
7
+ class _AnsiCode:
8
+ ESC = "\033"
9
+ RESET = f"{ESC}[0m"
10
+ @staticmethod
11
+ def build(mode: int = 0, fg: Optional[int] = None, bg: Optional[int] = None) -> str:
12
+ parts = []
13
+ if mode != 0:
14
+ parts.append(str(mode))
15
+ if fg is not None:
16
+ parts.append(str(fg))
17
+ if bg is not None:
18
+ parts.append(str(bg))
19
+ if parts:
20
+ return f"{_AnsiCode.ESC}[{';'.join(parts)}m"
21
+ return ""
22
+
23
+ def _ansi_return(data: str, text_color: Optional[int] = None, bg_color: Optional[int] = None, mode: int = 0) -> str:
24
+ """ 生成ANSI彩色文本(不自动输出)
25
+
26
+ 参数:
27
+ data: 要着色的文本内容
28
+ text_color: 前景色代码 (30-37普通色, 90-97亮色)
29
+ bg_color: 背景色代码 (40-47普通色, 100-107亮色)
30
+ mode: 显示方式 (0=默认,1=粗体,2=暗淡,3=斜体,4=下划线,5=闪烁,7=反色,8=隐藏,9=删除线)
31
+
32
+ 返回:
33
+ 带ANSI转义序列的字符串
34
+ """
35
+
36
+ if text_color is None and bg_color is None:
37
+ return data
38
+
39
+ ansi = _AnsiCode.build(mode, text_color, bg_color)
40
+ return f"{ansi}{data}{_AnsiCode.RESET}"
41
+
42
+ def _ansi_rgb(data: str, r: int, g: int, b: int, mode: int = 0) -> str:
43
+ """ 内部函数 """
44
+ if mode == 0:
45
+ return f"{_AnsiCode.ESC}[38;2;{r};{g};{b}m{data}{_AnsiCode.RESET}"
46
+ else:
47
+ return f"{_AnsiCode.ESC}[{mode};38;2;{r};{g};{b}m{data}{_AnsiCode.RESET}"
48
+
49
+ def color_rgb(data: str, r: int, g: int, b: int, mode: int = 0, newline: bool = True) -> None:
50
+ """ 输出 rgb 字符 """
51
+ print(_ansi_rgb(data, r, g, b, mode))
52
+ if newline:
53
+ print()
54
+
55
+ def color(data: str, text_color: Optional[int] = None, bg_color: Optional[int] = None, mode: int = 0, newline: bool =True) -> None:
56
+ """ 输出彩色字符到控制台
57
+
58
+ 参数:
59
+ data: 要输出的文本内容
60
+ text_color: 前景色代码 (30-37普通色, 90-97亮色)
61
+ bg_color: 背景色代码 (40-47普通色, 100-107亮色)
62
+ mode: 显示方式 (0=默认,1=粗体,2=暗淡,3=斜体,4=下划线,5=闪烁,7=反色,8=隐藏,9=删除线)
63
+ newline: 是否在输出后添加空行,默认True
64
+
65
+ 示例:
66
+ color("错误信息", text_color=31, mode=1) # 红色加粗
67
+ color("警告", text_color=33, bg_color=41) # 黄字红底
68
+ """
69
+
70
+ print(_ansi_return(data, text_color, bg_color, mode))
71
+ if newline:
72
+ print()
73
+
74
+ """ newline: 提高观感
75
+ 普通输出:
76
+ 1
77
+ 2
78
+ 3
79
+ 1-1
80
+ 2-1
81
+ Input: Luci_Code
82
+ newline 输出:
83
+ 1
84
+ 2
85
+ 3
86
+
87
+ 1-1
88
+ 2-1
89
+
90
+ Input: Luci_Code
91
+ """
92
+
93
+ def clear_screen() -> None:
94
+ """ 跨平台兼容清屏 """
95
+ if platform == "win32":
96
+ run(['cmd', '/c', 'cls'])
97
+ else:
98
+ run(['clear'])
99
+
100
+ def safe_input(prompt: str, text_color: Optional[int] = None, bg_color: Optional[int] = None, mode: int = 0) -> str:
101
+ """ 安全输出字符串 """
102
+ if text_color:
103
+ prompt = _ansi_return(prompt, text_color, bg_color, mode)
104
+ try:
105
+ return input(prompt)
106
+ except KeyboardInterrupt:
107
+ clear_screen()
108
+ color("退出成功(Ctrl + C)", 32, None, 1)
109
+ exit(0)
110
+ except EOFError:
111
+ clear_screen()
112
+ color("输入流关闭, 自动退出", 34, None, 1)
113
+ exit(0)
114
+
115
+ def _safe_number(prompt: str, convert_func, text_color: Optional[int] = None, bg_color: Optional[int] = None, mode: int = 0):
116
+ """ 内部函数:安全的数字输入 """
117
+ if convert_func is None:
118
+ raise ValueError("convert_func cannot be None")
119
+ if text_color:
120
+ prompt = _ansi_return(prompt, text_color, bg_color, mode)
121
+ while True:
122
+ try:
123
+ return convert_func(input(prompt))
124
+ except ValueError:
125
+ color("\n输入类型错误", 34, None, 1)
126
+ continue
127
+ except KeyboardInterrupt:
128
+ clear_screen()
129
+ color("退出成功(Ctrl + C)", 34, None, 1)
130
+ exit(0)
131
+ except EOFError:
132
+ clear_screen()
133
+ color("输入流关闭, 自动退出", 34, None, 1)
134
+ exit(0)
135
+
136
+ def safe_int(prompt: str, text_color: Optional[int] = None, bg_color: Optional[int] = None, mode: int = 0) -> int:
137
+ """ 安全输出整数 """
138
+ return _safe_number(prompt, int, text_color, bg_color, mode)
139
+
140
+ def safe_float(prompt: str, text_color: Optional[int] = None, bg_color: Optional[int] = None, mode: int = 0) -> float:
141
+ """ 安全输出浮点数 """
142
+ return _safe_number(prompt, float, text_color, bg_color, mode)
143
+
144
+ def cloudflare_play() -> None:
145
+ cloudflare_box = """
146
+ ┏━━━━━━━━━━━━━━┓
147
+ ┃ ┌┐ 请验证您是真人 ☁️ ┃
148
+ ┃ └┘ cloudflare ┃
149
+ ┗━━━━━━━━━━━━━━┛
150
+ """
151
+ color(cloudflare_box, 32, None, 1)
152
+
153
+ # -- 测试部分 -- #
154
+ if __name__ == "__main__":
155
+ print("=== 测试基本颜色 ===")
156
+ color("红色文本", text_color=31)
157
+ color("绿色加粗", text_color=32, mode=1)
158
+ color("黄字红底", text_color=33, bg_color=41)
159
+
160
+ print("\n=== 测试RGB颜色 ===")
161
+ color_rgb("RGB红色", r=255, g=0, b=0)
162
+ color_rgb("RGB绿色加粗", r=0, g=255, b=0, mode=1)
163
+
164
+ print("\n=== 测试清屏 ===")
165
+ input("按回车清屏...")
166
+ clear_screen()
167
+ color("清屏成功", text_color=32, mode=1)
168
+
169
+ print("\n=== 测试CloudFlare样式 ===")
170
+ cloudflare_play()
171
+
172
+ print("\n=== 测试输入函数 ===")
173
+ name = safe_input("请输入名字: ", text_color=36)
174
+ age = safe_int("请输入年龄: ", text_color=33)
175
+ height = safe_float("请输入身高(m): ", text_color=34)
176
+
177
+ color(f"\n你好 {name}, 年龄 {age}, 身高 {height}m", text_color=32, mode=1)
178
+
179
+ print("\n所有测试完成!")
@@ -0,0 +1,120 @@
1
+ Metadata-Version: 2.4
2
+ Name: Luci-Code-Tools
3
+ Version: 1.1.3
4
+ Summary: 安全输入工具库,支持彩色输出,KeyboardInterrupt保护等
5
+ Home-page: https://github.com/Luci-Codeing/code_tools
6
+ Author: Luci_Code
7
+ Author-email: 3967742419@qq.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENCE
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: classifier
16
+ Dynamic: description
17
+ Dynamic: description-content-type
18
+ Dynamic: home-page
19
+ Dynamic: license-file
20
+ Dynamic: requires-python
21
+ Dynamic: summary
22
+
23
+ [![PyPI version](https://badge.fury.io/py/luci-code-tools.svg)](https://pypi.org/project/luci-code-tools/)
24
+
25
+ # Luci_Code_Tools
26
+
27
+ ## 介绍:
28
+
29
+ 给初学者制作的 *Python* 工具库, 基于 Python 3.13.3 制作
30
+
31
+ ### 安装 & 导入
32
+
33
+ ```bash
34
+ pip install Luci-Code-Tools
35
+ ```
36
+
37
+ ```python
38
+ from Luci_code_tools import *
39
+ # 或者
40
+ import Luci_code_tools
41
+ ```
42
+
43
+ # 内容
44
+
45
+ **函数**
46
+
47
+ **safe_\*** = **safe_input, safe_int, safe_float**
48
+
49
+ | 名称 | 作用 | 参数 |
50
+ | --- | --- | --- |
51
+ | color | 输出ANSI彩色字符 | data, text_color, bg_color, mode, newline |
52
+ | color_rgb | 输出RGB彩色字符 | data, r, g, b, mode, newline |
53
+ | clear_screen | 可跨平台的清屏 | None (没有参数) |
54
+ | safe_* | 安全的输入, 防止Ctrl + C和输入流关闭等报错 | prompt, text_color, bg_color, mode |
55
+ | cloudflare_play | 输出 CloudFlare 人机验证 | None (没有参数) |
56
+
57
+ **提示**: ***参数需要按照顺序填***
58
+
59
+ # < TODO >
60
+
61
+ ---
62
+
63
+ # 其他
64
+
65
+ **ANSI常用序列**
66
+ *提示: 90-97 为亮色前景色,100-107 为亮色背景色*
67
+
68
+ | 前景色 | 效果 |
69
+ | --- | --- |
70
+ | 30 | 黑色 |
71
+ | 31 | 红色 |
72
+ | 32 | 绿色 |
73
+ | 33 | 黄色 |
74
+ | 34 | 蓝色 |
75
+ | 35 | 紫色 |
76
+ | 36 | 青色 |
77
+ | 37 | 白色 |
78
+
79
+ | 显示方式 | 效果 |
80
+ | --- | --- |
81
+ | 0 | 默认 |
82
+ | 1 | 粗体 + 高亮 |
83
+ | 2 | 暗淡 |
84
+ | 3 | 斜体(部分终端不支持) |
85
+ | 4 | 下划线 |
86
+ | 5 | 闪烁 |
87
+ | 6 | 快闪(部分终端不支持)
88
+ | 7 | 反色(前景色与背景色互换) |
89
+ | 8 | 隐藏 |
90
+ | 9 | 删除线 |
91
+
92
+ | 背景色 | 效果 |
93
+ | --- | --- |
94
+ | 40 | 黑色 |
95
+ | 41 | 红色 |
96
+ | 42 | 绿色 |
97
+ | 43 | 黄色 |
98
+ | 44 | 蓝色 |
99
+ | 45 | 紫色 |
100
+ | 46 | 青色 |
101
+ | 47 | 白色 |
102
+
103
+ ---
104
+
105
+ # 制作者 & 感谢名单
106
+
107
+ | 作者 | 分工 |
108
+ | --- | --- |
109
+ | DeepSeek | 检查 |
110
+ | DeepSeek | 改进 |
111
+ | Luci_Code | 代码 |
112
+ | Luci_Code | 文档 |
113
+ | Luci_Code | 思路 |
114
+ | Luci_Code | 上传 |
115
+
116
+ ---
117
+
118
+ # 感谢
119
+
120
+ ***<感谢您的阅读,我是Luci_Code, 一名2014年出生的开发者 >***
@@ -0,0 +1,6 @@
1
+ Luci_code_tools.py,sha256=MEdfnmMIz0_Ut3uyZXs8JGitDs8Q41lcel0NsjBgcJc,6046
2
+ luci_code_tools-1.1.3.dist-info/licenses/LICENCE,sha256=b2hWWCM1tFEAQ-J6ZOntAAIE5pXtuaeAYUvxGm0CGLA,1067
3
+ luci_code_tools-1.1.3.dist-info/METADATA,sha256=7j98oRZAdA9--O6ewErla1ANduiSXSWQEHGpfRs0kMw,2561
4
+ luci_code_tools-1.1.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ luci_code_tools-1.1.3.dist-info/top_level.txt,sha256=xbrPrFxDcMxHoPCiSfuJCZ2HjW995UF_lVB9BrSs7wo,16
6
+ luci_code_tools-1.1.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 [Luci_Code]
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.
@@ -0,0 +1 @@
1
+ Luci_code_tools