Luci-Code-Tools 2.2.9__tar.gz → 2.3.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.
@@ -1,1077 +1,1077 @@
1
- Metadata-Version: 2.4
2
- Name: Luci-Code-Tools
3
- Version: 2.2.9
4
- Summary: 一个简单的工具库 / A Eazy Tools Module
5
- Home-page: https://github.com/Luci-Code-2014
6
- Author: Luci_Code
7
- Author-email: 3967742419@qq.com
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.6
12
- Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
- Dynamic: author
15
- Dynamic: author-email
16
- Dynamic: classifier
17
- Dynamic: description
18
- Dynamic: description-content-type
19
- Dynamic: home-page
20
- Dynamic: license-file
21
- Dynamic: requires-python
22
- Dynamic: summary
23
-
24
- [![PyPI version](https://badge.fury.io/py/Luci\_Code_Tools.svg)](https://pypi.org/project/Luci\_Code_Tools/)
25
-
26
- [![Python Version](https://img.shields.io/badge/Python-3.6+-blue.svg)]()
27
-
28
- [![License](https://img.shields.io/badge/License-MIT-green.svg)]()
29
-
30
- [![Cat](https://img.shields.io/badge/Cat-Approved-orange.svg)]()
31
-
32
- ---
33
-
34
- # 中文文档
35
-
36
- **Chinese Document**
37
-
38
- ---
39
-
40
- **English Document use DeepSeek AI and Google Translate**
41
-
42
- **There may be some inaccuracies**
43
-
44
- ---
45
-
46
- # 欢迎 💎
47
-
48
- **感谢你点击这个项目**
49
-
50
- **这是一个 *工具箱 / 快捷工具* 类型的项目**
51
-
52
- **带有 *6* 个函数可使用**
53
-
54
- # Luci\_Code_Tools 🔍
55
-
56
- **代码花费 *9000+* 字符数**
57
-
58
- ***2026 年 5 月 9 日*开始维护**
59
-
60
- *27* 个异常处理, 个个定制的异常返回 **(触发异常时返回的操作)**
61
-
62
- # 许可证 📄
63
-
64
- 使用 **MIT License** 许可证
65
-
66
- # 设备 📱 💻
67
-
68
- 早期版本 (**2.1.5** 及更早) 使用 *Android* 上的 ***MT 管理器*** (软件开发者: **Bin**)
69
-
70
- 早期版本以后的版本使用 (**版本 >=2.1.6**) ***Visual Studio Code*** 进行编写 (软件开发商: **Microsoft Corporation**)
71
-
72
- ## 设备信息
73
-
74
- Android 设备信息: Android 13
75
-
76
- Windows 设备信息: Windows 10 22H2
77
-
78
- # 作者 ヾ(≧▽≦*)o
79
-
80
- 作者名字叫: **Luci\_Code**
81
-
82
- **2014** 年出生 🐱
83
-
84
- 此代码的编写者 : Luci\_Code
85
-
86
- 此文档的编写者 : Luci\_Code
87
-
88
- Github 链接: **https://github.com/Luci-Code-2014/**
89
-
90
- ---
91
-
92
- # 代码介绍 🎮
93
-
94
- 项目文件夹 📂:
95
-
96
- Luci\_Code_tools.py | 代码主文件
97
-
98
- 200+ 行数运行的代码文件 🐱
99
-
100
- setup.py | 上传信息
101
-
102
- 在 PyPI 上上传时传输的信息
103
-
104
- 包括 适用版本, 许可证信息等
105
-
106
- 你可以在此模块的网页界面左边部分看到他给予的信息喵🐱
107
-
108
- README.md | 此文档
109
-
110
- 这就是你现在看到的文档喵🐱
111
-
112
- LICENSE | 许可证 (MIT)
113
-
114
- *MIT* 许可证是 目前 **(2026 年)** 最自由的许可证
115
-
116
- 他不要求你获得授权
117
-
118
- 他只要求在转载时能加一个来源喵🐱
119
-
120
-
121
- ## 主代码
122
-
123
- **27** 个异常处理
124
-
125
- 包括:
126
-
127
- *结果* 板块为代码中给出的结果
128
-
129
- 在原本的代码中所有**异常处理**的结果都为报错
130
-
131
- **错误退出**是指在错误的状态的报出错误并退出
132
-
133
- 比如程序被不正确的方式报错了, 这时候就应该*错误退出*程序, 会被 SystemExit 捕获
134
-
135
- | 报错 | 意思 | 结果 |
136
- | --- | --- | --- |
137
- | ValueError | 输入的值与期待的值类型错误 | 重试 |
138
- | KeyboardInterrupt | 在 Ctrl + C 时, 命令行会被中断而显示的报错 | 退出 + 提示语 |
139
- | EOFError | 意思是 End of file , 代表输入流被关闭 | 退出 + 提示语 |
140
- | MemoryError | 内存过高导致的错误, 比如你输入了一个极高长度的字符超过了你的内存大小 | 退出(错误退出) + 提示语 |
141
- | SystemError | Python 解释器损坏 | 退出 + 提示语 |
142
- | OSError | 你系统炸了 😂 (可能是系统文件损坏问题引起的错误) | 退出(错误退出) + 提示语 |
143
-
144
- 等错误, 总共有 **27** 种异常处理, 正常情况下 ***几乎不可能报错***
145
-
146
- # 📦 安装方式 & 导入方式
147
-
148
- ```bash
149
- pip install Luci-Code-Tools
150
- ```
151
-
152
- 默认会安装最新版
153
-
154
- 你可以通过把
155
-
156
- ```bash
157
- pip install <包名>
158
- ```
159
-
160
- 改成
161
-
162
- ```bash
163
- pip install <包名>==<版本号>
164
- ```
165
-
166
- 来安装对应的版本
167
-
168
- ## 导入 & 引用
169
-
170
- ```python
171
-
172
- # 注: 所有方式的示例函数为 color 函数
173
-
174
- # 导入
175
- import Luci_Code_tools
176
- Luci_Code_tools.color("HelloWorld", 32, None, 1, 2)
177
-
178
- # 导入 + as
179
- import Luci_Code_tools as lct
180
- lct.color("HelloWorld", 32, None, 1, 2)
181
-
182
- # 引用
183
- from Luci_Code_tools import color
184
- color("HelloWorld", 32, None, 1, 2)
185
-
186
- # 引用 + as
187
- from Luci_Code_tools import color as cl
188
- cl("HelloWorld", 32, None, 1, 2)
189
-
190
- ```
191
-
192
- ---
193
-
194
- # 参数介绍
195
-
196
- line 的输出样式是
197
-
198
- {
199
-
200
- "line": 0,
201
-
202
- "data": "Hello",
203
-
204
- "data": "World",
205
-
206
- "output": 2
207
-
208
- } "output": 2 等于两个输出函数
209
-
210
- 输出效果:
211
-
212
- HelloWorld ("Hello" 和 "World" 是两个字符串)
213
-
214
- {
215
-
216
- "line": 1,
217
-
218
- "data": "Hello",
219
-
220
- "data": "World",
221
-
222
- "output": 2
223
-
224
- } "output": 2 等于两个输出函数
225
-
226
- 输出效果:
227
-
228
- Hello
229
-
230
- (这里的空间其实不空行)
231
-
232
- World
233
-
234
- {
235
-
236
- "line": 2,
237
-
238
- "data": "Hello",
239
-
240
- "data": "World",
241
-
242
- "output": 2
243
-
244
- } "output": 2 等于两个输出函数
245
-
246
- 输出效果:
247
-
248
- Hello
249
-
250
- (Markdown 格式限制, 中间其实有空着一行)
251
-
252
- World
253
-
254
- line 参数可以调更高, 但是由于篇幅限制我需要减少测试喵🐱
255
-
256
- 通过数字个性化调整空行数来提高辨识度
257
-
258
- ## 函数参数
259
-
260
- 我们先列出目前代码中所用的函数
261
-
262
- ## 函数
263
-
264
- - color_rgb
265
-
266
- - color
267
-
268
- - clear_screen
269
-
270
- - safe_input
271
-
272
- - safe_int
273
-
274
- - safe_float
275
-
276
- ## 所有参数
277
-
278
- ---
279
-
280
- 我们首先介绍 **color_rgb**
281
-
282
- - color_rgb
283
-
284
- 这个函数是一个管理 RGB 彩色输出的函数, 使用 **ANSI 转义序列 + 参数** 完成的构建
285
-
286
- 参数包括:
287
-
288
- data r g b mode line
289
-
290
- - data
291
-
292
- data 参数是控制 **输入的内容** 的参数
293
-
294
- - r
295
-
296
- - g
297
-
298
- - b
299
-
300
- 这三个参数按照 R, G, B 三个字符的顺序写, 比如 255, 0, 0 为**纯红色**
301
-
302
- - mode
303
-
304
- mode 参数是控制输出模式的参数, 具体输出模式参数表在最后
305
-
306
- - line
307
-
308
- line 参数输入整数, 具体信息在 **"参数介绍"** 部分片段
309
-
310
- ---
311
-
312
- - color
313
-
314
- 此函数是一个管理 ANSI 转义序列彩色字符的函数 🤔
315
-
316
- - data
317
-
318
- 管理在彩色字符输出时输出的字符串
319
-
320
- - text_color
321
-
322
- 通过 ANSI 颜色码来控制输出的颜色, 不用调来调去, 详细参数在最后的参数表
323
-
324
- - bg_color
325
-
326
- 通过 ANSI 颜色码来控制输出时背景的颜色, 详细参数在最后的参数表
327
-
328
- - mode
329
-
330
- 通过 ANSI 转义序列的输出方式来控制输出 / 显示的方式
331
-
332
- - line
333
-
334
- 和上一位 color_rgb 是一个意思, 都可以控制输出时间隔的行数
335
-
336
- ---
337
-
338
- - clear_screen
339
-
340
- clear_screen 没有参数, 但是我带来了函数介绍
341
-
342
- **函数介绍**
343
-
344
- 此函数有:
345
-
346
- > 判断系统自动使用相对应清屏命令
347
-
348
- 比如:
349
-
350
- Android -> clear (Linux 内核)
351
-
352
- Linux -> clear
353
-
354
- Windows -> cls
355
-
356
- 来切换使用的清屏命令
357
-
358
- > 绝对的防注入, 列表控制清屏的参数与命令
359
-
360
- > 即使是没有命令行的环境 (无法使用 clear / cls 命令的环境) 也可以使用 shutil 模块来检测终端高度并输出对应的空行数
361
-
362
- > 甚至不能获取到终端高度也能输出 250 个空行来 "清屏"
363
-
364
- ---
365
-
366
- - safe_input
367
-
368
- - safe_int
369
-
370
- - safe_float
371
-
372
- 这些 **safe_\*** 的参数都是一样的:
373
-
374
- prompt | 提示词
375
-
376
- text_color | 提示词颜色
377
-
378
- bg_color | 提示词背景颜色
379
-
380
- mode | 提示词输出方式
381
-
382
- - prompt
383
-
384
- prompt 跟 data 参数是一个意思喵🐱
385
-
386
- - text_color
387
-
388
- - bg_color
389
-
390
- - mode
391
-
392
- 这三个参数和 color, color_rgb 中的这三个参数是一样的, 代表的意思相同喵🐱
393
-
394
- ---
395
-
396
- # 参数表
397
-
398
- ## 前景色
399
-
400
- | 前景色 - 值 | 效果 |
401
- | --- | --- |
402
- | 30 | 黑色 |
403
- | 31 | 红色 |
404
- | 32 | 绿色 |
405
- | 33 | 黄色 |
406
- | 34 | 蓝色 |
407
- | 35 | 紫色 |
408
- | 36 | 青色 |
409
- | 37 | 白色 |
410
-
411
- ## 前景色 - 浅色
412
-
413
- | 前景色 - 值 | 效果 |
414
- | --- | --- |
415
- | 90 | 深灰色 |
416
- | 91 | 浅红色 |
417
- | 92 | 浅绿色 |
418
- | 93 | 浅黄色 |
419
- | 94 | 浅蓝色 |
420
- | 95 | 浅紫色 |
421
- | 96 | 浅青色 |
422
- | 97 | 浅灰色 |
423
-
424
- ## 背景色
425
-
426
- | 背景色 - 值 | 效果 |
427
- | --- | --- |
428
- | 40 | 黑色 |
429
- | 41 | 红色 |
430
- | 42 | 绿色 |
431
- | 43 | 黄色 |
432
- | 44 | 蓝色 |
433
- | 45 | 紫色 |
434
- | 46 | 青色 |
435
- | 47 | 白色 |
436
-
437
- ## 背景色 - 浅色
438
-
439
- | 背景色 - 值 | 效果 |
440
- | --- | --- |
441
- | 100 | 深灰色 |
442
- | 101 | 浅红色 |
443
- | 102 | 浅绿色 |
444
- | 103 | 浅黄色 |
445
- | 104 | 浅蓝色 |
446
- | 105 | 浅紫色 |
447
- | 106 | 浅青色 |
448
- | 107 | 纯白色 |
449
-
450
- ## 输出方式
451
-
452
- | 显示方式 - 值 | 效果 |
453
- | --- | --- |
454
- | 0 | 默认 |
455
- | 1 | 高亮 + 加粗 |
456
- | 2 | 暗淡 |
457
- | 3 | 斜体 (部分终端可能不支持) |
458
- | 4 | 下划线 |
459
- | 5 | 闪烁 |
460
- | 6 | 快闪(部分终端可能不支持) |
461
- | 7 | 反色(前景色与背景色互换) |
462
- | 8 | 隐藏 |
463
- | 9 | 删除线 |
464
-
465
- ---
466
-
467
- # 制作人员 & 感谢名单 (以贡献程度排名从上到下)
468
-
469
- | 人员 | 提供 |
470
- | --- | --- |
471
- | DeepSeek | 构建 & 打包 & 上传教程 |
472
- | DeepSeek | 提供改进意见 |
473
- | DeepSeek | 环境帮助 |
474
- | Luci\_Code | 编写 |
475
- | Luci\_Code | 打包 |
476
- | Luci\_Code | 制作 |
477
- | Luci\_Code | 构建 |
478
- | Luci\_Code | 上传 |
479
- | Luci\_Code | 构思 |
480
-
481
- ---
482
-
483
- # 快速上手
484
-
485
- ## 输入输出
486
-
487
- ```python
488
- from Luci_Code_tools import color, safe_input
489
-
490
- text = safe_input("请输入文本: ", 32, None, 1)
491
- color(f"你输入了 {text}", 32, None, 1, 2)
492
- ```
493
-
494
- ## 计算器
495
-
496
- ```python
497
- from Luci_Code_tools import color, safe_float, safe_input
498
- from sys import exit
499
-
500
- color("=== 计算器 ===", 32, None, 1, 2)
501
- while True:
502
- num1 = safe_float("请输入第一位数字: ", 32, None, 1)
503
- num2 = safe_float("请输入第二位数字: ", 32, None, 1)
504
- operators = safe_input("请输入运算符(+, -, *, /, 输入 quit 退出): ")
505
- if operators == "+":
506
- color(f"结果为: {num1 + num2}\n==========", 32, None, 1, 2)
507
- continue
508
- elif operators == "-":
509
- color(f"结果为: {num1 - num2}\n==========", 32, None, 1, 2)
510
- continue
511
- elif operators == "*":
512
- color(f"结果为: {num1 * num2}\n==========", 32, None, 1, 2)
513
- continue
514
- elif operators == "/":
515
- if num2 == 0:
516
- color("除数不能等于 0\n==========", 33, None, 1, 2)
517
- continue
518
- else:
519
- color(f"结果为: {num1 / num2}\n==========", 32, None, 1, 2)
520
- continue
521
- elif operators == "quit":
522
- color("=== 退出成功 ===", 32, None, 1, 2)
523
- exit(0)
524
- else:
525
- color("没有这个运算符!\n==========", 33, None, 1, 2)
526
- continue
527
- ```
528
-
529
- ## 文件读写
530
-
531
- ```python
532
- from Luci_Code_tools import color
533
- from os import remove
534
- from json import load, dump, JSONDecodeError
535
-
536
- JSON = {
537
- "test": "This is Test content",
538
- "test2": "This is Test content 2"
539
- }
540
-
541
- FILE_PATH = "user.json"
542
-
543
- def fix_json(prompt: str) -> None:
544
- color(prompt, 33, None, 1, 2)
545
- with open(FILE_PATH, "w", encoding="utf-8") as f:
546
- dump(JSON, f, ensure_ascii=False, indent=4, sort_keys=True)
547
- color("修复成功! 请重启程序", 32, None, 1)
548
-
549
- try:
550
- with open(FILE_PATH, "r", encoding="utf-8") as f:
551
- data = load(f)
552
- except FileNotFoundError:
553
- fix_json("文件不存在, 正在修复中...")
554
- except JSONDecodeError:
555
- fix_json("Json 文件格式或内容错误")
556
- else:
557
- content_1 = data["test"]
558
- content_2 = data["test2"]
559
- color(f"内容1: {content_1}\n内容2: {content_2}\n\n测试成功!", 32, None, 1, 2)
560
- remove(FILE_PATH)
561
- ```
562
-
563
- ---
564
-
565
- # English Document
566
-
567
- **英语文档**
568
-
569
- ---
570
-
571
- # Welcome 💎
572
-
573
- **Thanks for checking out this project**
574
-
575
- **This is a *toolbox / quick-utility* style project**
576
-
577
- **Features *6* functions for use**
578
-
579
- # Luci\_Code_Tools 🔍
580
-
581
- **Codebase spans over *9,000* characters**
582
-
583
- **Maintenance began on *May 9, 2026***
584
-
585
- *27* exception handlers, each with a custom return value **(the output returned when an exception is triggered)**
586
-
587
- # License 📄
588
-
589
- Uses the **MIT License**
590
-
591
- # Devices 📱 💻
592
-
593
- Early versions (**2.1.5** and earlier) were developed using ***MT Manager*** on *Android* (Developer: **Bin**)
594
-
595
- Versions from **2.1.6** onwards were written using ***Visual Studio Code*** (Developer: **Microsoft Corporation**)
596
-
597
- ## Device Information
598
-
599
- Android device info: Android 13
600
-
601
- Windows device info: Windows 10 22H2
602
-
603
- # Author ヾ(≧▽≦*)o
604
-
605
- Author's name: **Luci\_Code**
606
-
607
- Born in **2014** 🐱
608
-
609
- Code written by: Luci\_Code
610
-
611
- Documentation written by: Luci\_Code
612
-
613
- GitHub link: **https://github.com/Luci-Code-2014/**
614
-
615
- ---
616
-
617
- # Code Overview 🎮
618
-
619
- Project folders/files 📂:
620
-
621
- Luci\_Code_tools.py | Main code file
622
-
623
- A script spanning over 200 lines of code 🐱
624
-
625
- setup.py | Upload metadata
626
-
627
- Information transmitted during PyPI upload
628
-
629
- Includes compatible versions, license details, etc.
630
-
631
- You can view this information on the left side of the module's webpage 🐱
632
-
633
- README.md | This document
634
-
635
- The very document you are reading right now 🐱
636
-
637
- LICENSE | License (MIT)
638
-
639
- The *MIT* License is currently **(as of 2026)** the most permissive license available
640
-
641
- It does not require you to obtain explicit authorization
642
-
643
- It only asks that you credit the source when redistributing 🐱
644
-
645
- ## Main Code
646
-
647
- **27** exception handlers
648
-
649
- Including:
650
-
651
- *Results* The sections below describe the results defined in the code.
652
-
653
- In the original code, all **exception handling** scenarios result in an error report.
654
-
655
- **Error Exit** refers to raising an error due to an invalid state and subsequently terminating the program.
656
-
657
- For instance, if the program encounters an improper error condition, it should perform an *Error Exit*; this is caught by `SystemExit`.
658
-
659
- | Error | Meaning | Result |
660
- | --- | --- | --- |
661
- | ValueError | Input value type does not match expected type | Retry |
662
- | KeyboardInterrupt | Error displayed when the command line is interrupted (e.g., Ctrl + C) | Exit + Message |
663
- | EOFError | End of File; indicates the input stream has been closed | Exit + Message |
664
- | MemoryError | Error caused by excessive memory usage (e.g., inputting a string exceeding available memory) | Exit (Error Exit) + Message |
665
- | SystemError | Python interpreter corruption | Exit + Message |
666
- | OSError | Your system crashed 😂 (likely caused by corrupted system files) | Exit (Error Exit) + Message |
667
-
668
- There are **27** types of exception handling in total; under normal circumstances, errors ***almost never occur***.
669
-
670
- # 📦 Installation & Import
671
-
672
- ```bash
673
- pip install Luci-Code-Tools
674
- ```
675
-
676
- This installs the latest version by default.
677
-
678
- You can install a specific version by changing
679
-
680
- ```bash
681
- pip install <package_name>
682
- ```
683
-
684
- to
685
-
686
- ```bash
687
- pip install <package_name>==<version_number>
688
- ```
689
-
690
- ## Import & Reference
691
-
692
- ```python
693
-
694
- # Note: The example function used in all cases is the 'color' function
695
-
696
- # Import
697
- import Luci_Code_tools
698
- Luci_Code_tools.color("HelloWorld", 32, None, 1, 2)
699
-
700
- # Import + as
701
- import Luci_Code_tools as lct
702
- lct.color("HelloWorld", 32, None, 1, 2)
703
-
704
- # Reference
705
- from Luci_Code_tools import color
706
- color("HelloWorld", 32, None, 1, 2)
707
-
708
- # Reference + as
709
- from Luci_Code_tools import color as cl
710
- cl("HelloWorld", 32, None, 1, 2)
711
-
712
- ```
713
-
714
- ---
715
-
716
- # Parameter Introduction
717
-
718
- The output style for `line` is:
719
-
720
- ```json
721
- {
722
- "line": 0,
723
- "data": "Hello",
724
- "data": "World",
725
- "output": 2
726
- }
727
- ```
728
- `"output": 2` corresponds to two output functions.
729
-
730
- Output effect:
731
-
732
- HelloWorld ("Hello" and "World" are two separate strings)
733
-
734
- ```json
735
- {
736
- "line": 1,
737
- "data": "Hello",
738
- "data": "World",
739
- "output": 2
740
- }
741
- ```
742
- `"output": 2` corresponds to two output functions.
743
-
744
- Output effect:
745
-
746
- Hello
747
-
748
- (There is actually no blank line here)
749
-
750
- World
751
-
752
- ```json
753
- {
754
- "line": 2,
755
- "data": "Hello",
756
- "data": "World",
757
- "output": 2
758
- }
759
- ```
760
- `"output": 2` corresponds to two output functions.
761
-
762
- Output effect:
763
-
764
- Hello
765
-
766
- (There is actually a blank line in between)
767
-
768
- World
769
-
770
- The `line` parameter can be set higher, but I need to limit the number of tests due to space constraints 🐱
771
-
772
- Adjust the number of blank lines numerically to improve readability.
773
-
774
- ## Function Parameters
775
-
776
- Let's first list the functions currently used in the code.
777
-
778
- ## Functions
779
-
780
- - color_rgb
781
-
782
- - color
783
-
784
- - clear_screen
785
-
786
- - safe_input
787
-
788
- - safe_int
789
-
790
- - safe_float
791
-
792
- ## All Parameters
793
-
794
- ---
795
-
796
- First, let's introduce **color_rgb**
797
-
798
- - color_rgb
799
-
800
- This function manages RGB color output; it is constructed using **ANSI escape sequences + parameters**.
801
-
802
- Parameters include:
803
-
804
- data r g b mode line
805
-
806
- - data
807
-
808
- The `data` parameter controls the **content to be output**.
809
-
810
- - r
811
-
812
- - g
813
-
814
- - b
815
-
816
- These three parameters are specified in the order of R, G, and B; for example, `255, 0, 0` represents **pure red**.
817
-
818
- - mode
819
-
820
- The `mode` parameter controls the output mode; a table of specific output modes is provided at the end.
821
-
822
- - line
823
-
824
- The `line` parameter accepts an integer; specific details can be found in the **"Parameter Introduction"** section above.
825
-
826
- ---
827
-
828
- - color
829
-
830
- This function manages colored text using ANSI escape sequences 🤔
831
-
832
- - data
833
-
834
- Manages the string to be output with color formatting.
835
-
836
- - text_color
837
-
838
- Controls the output color using ANSI color codes; no need for complex adjustments. Detailed parameters are in the parameter table at the end.
839
-
840
- - bg_color
841
-
842
- Controls the background color of the output using ANSI color codes. Detailed parameters are in the parameter table at the end.
843
-
844
- - mode
845
-
846
- Controls the output/display style using ANSI escape sequences.
847
-
848
- - line
849
-
850
- Serves the same purpose as the `color_rgb` parameter mentioned earlier; both control the number of blank lines between outputs.
851
-
852
- ---
853
-
854
- - clear_screen
855
-
856
- `clear_screen` takes no arguments, but here is an introduction to the function.
857
-
858
- **Function Introduction**
859
-
860
- This function:
861
-
862
- > Automatically detects the system and uses the corresponding screen-clearing command.
863
-
864
- For example:
865
-
866
- Android -> `clear` (Linux kernel)
867
-
868
- Linux -> `clear`
869
-
870
- Windows -> `cls`
871
-
872
- It switches the command used based on the OS.
873
-
874
- > Ensures absolute protection against injection attacks by using a controlled list of parameters and commands for clearing the screen.
875
-
876
- > Can use the `shutil` module to detect terminal height and output the appropriate number of blank lines, even in environments without a command-line interface (where `clear` or `cls` commands are unavailable).
877
-
878
- > Can output 250 blank lines to "clear the screen" even if the terminal height cannot be detected.
879
-
880
- ---
881
-
882
- - safe_input
883
-
884
- - safe_int
885
-
886
- - safe_float
887
-
888
- These `safe_*` functions share the same parameters:
889
-
890
- prompt | Prompt text
891
-
892
- text_color | Prompt text color
893
-
894
- bg_color | Prompt background color
895
-
896
- mode | Prompt output style
897
-
898
- - prompt
899
-
900
- The `prompt` parameter serves the same purpose as the `data` parameter.
901
-
902
- - text_color
903
-
904
- - bg_color
905
-
906
- - mode
907
-
908
- These three parameters are identical to the corresponding ones in `color` and `color_rgb`, serving the same function.
909
-
910
- ---
911
-
912
- # Parameter Table
913
-
914
- ## Foreground Color
915
-
916
- | Foreground Color - Value | Effect |
917
- | --- | --- |
918
- | 30 | Black |
919
- | 31 | Red |
920
- | 32 | Green |
921
- | 33 | Yellow |
922
- | 34 | Blue |
923
- | 35 | Purple |
924
- | 36 | Cyan |
925
- | 37 | White |
926
-
927
- ## Foreground Color - Light/Bright
928
-
929
- | Foreground Color - Value | Effect |
930
- | --- | --- |
931
- | 90 | Dark gray |
932
- | 91 | Light red |
933
- | 92 | Light green |
934
- | 93 | Light yellow |
935
- | 94 | Light blue |
936
- | 95 | Light purple |
937
- | 96 | Light cyan |
938
- | 97 | Light gray |
939
-
940
- ## Background Color
941
-
942
- | Background Color - Value | Effect |
943
- | --- | --- |
944
- | 40 | Black |
945
- | 41 | Red |
946
- | 42 | Green |
947
- | 43 | Yellow |
948
- | 44 | Blue |
949
- | 45 | Purple |
950
- | 46 | Cyan |
951
- | 47 | White |
952
-
953
- ## Background Color - Light Shades
954
-
955
- | Background Color - Value | Effect |
956
- | --- | --- |
957
- | 100 | Dark gray |
958
- | 101 | Light red |
959
- | 102 | Light green |
960
- | 103 | Light yellow |
961
- | 104 | Light blue |
962
- | 105 | Light purple |
963
- | 106 | Light cyan |
964
- | 107 | Pure white |
965
-
966
- ## Output Mode
967
-
968
- | Display Mode - Value | Effect |
969
- | --- | --- |
970
- | 0 | Default |
971
- | 1 | Highlight + Bold |
972
- | 2 | Dim |
973
- | 3 | Italic (may not be supported by some terminals) |
974
- | 4 | Underline |
975
- | 5 | Blink |
976
- | 6 | Rapid blink (may not be supported by some terminals) |
977
- | 7 | Invert (swap foreground and background colors) |
978
- | 8 | Hidden |
979
- | 9 | Strikethrough |
980
-
981
- ---
982
-
983
- # Credits & Acknowledgments (Ranked by contribution level, top to bottom)
984
-
985
- | Person/Entity | Contribution |
986
- | --- | --- |
987
- | DeepSeek | Build, packaging, and upload tutorial |
988
- | DeepSeek | Provided improvement suggestions |
989
- | DeepSeek | Environment help |
990
- | Luci\_Code | Writing |
991
- | Luci\_Code | Packaging |
992
- | Luci\_Code | Creation |
993
- | Luci\_Code | Building |
994
- | Luci\_Code | Uploading |
995
- | Luci\_Code | Conceptualization |
996
-
997
- ---
998
-
999
- # Quick Start
1000
-
1001
- ## Input and Output
1002
-
1003
- ```python
1004
- from Luci_Code_tools import color, safe_input
1005
-
1006
- text = safe_input("Please enter text: ", 32, None, 1)
1007
- color(f"You entered {text}", 32, None, 1, 2)
1008
- ```
1009
-
1010
- ## Calculator
1011
-
1012
- ```python
1013
- from Luci_Code_tools import color, safe_float, safe_input
1014
- from sys import exit
1015
-
1016
- color("=== Calculator ===", 32, None, 1, 2)
1017
- while True:
1018
- num1 = safe_float("Enter the first number: ", 32, None, 1)
1019
- num2 = safe_float("Enter the second number: ", 32, None, 1)
1020
- operators = safe_input("Enter operator (+, -, *, /, type 'quit' to exit): ")
1021
- if operators == "+":
1022
- color(f"Result: {num1 + num2}\n==========", 32, None, 1, 2)
1023
- continue
1024
- elif operators == "-":
1025
- color(f"Result: {num1 - num2}\n==========", 32, None, 1, 2)
1026
- continue
1027
- elif operators == "*":
1028
- color(f"Result: {num1 * num2}\n==========", 32, None, 1, 2)
1029
- continue
1030
- elif operators == "/":
1031
- if num2 == 0:
1032
- color("Divisor cannot be zero\n==========", 33, None, 1, 2)
1033
- continue
1034
- else:
1035
- color(f"Result: {num1 / num2}\n==========", 32, None, 1, 2)
1036
- continue
1037
- elif operators == "quit":
1038
- color("=== Exit successful ===", 32, None, 1, 2)
1039
- exit(0)
1040
- else:
1041
- color("Invalid operator!\n==========", 33, None, 1, 2)
1042
- continue
1043
- ```
1044
-
1045
- ## File Read and Write
1046
-
1047
- ```python
1048
- from Luci_Code_tools import color
1049
- from os import remove
1050
- from json import load, dump, JSONDecodeError
1051
-
1052
- JSON = {
1053
- "test": "This is Test content",
1054
- "test2": "This is Test content 2"
1055
- }
1056
-
1057
- FILE_PATH = "user.json"
1058
-
1059
- def fix_json(prompt: str) -> None:
1060
- color(prompt, 33, None, 1, 2)
1061
- with open(FILE_PATH, "w", encoding="utf-8") as f:
1062
- dump(JSON, f, ensure_ascii=False, indent=4, sort_keys=True)
1063
- color("Repair successful! Please restart the program", 32, None, 1)
1064
-
1065
- try:
1066
- with open(FILE_PATH, "r", encoding="utf-8") as f:
1067
- data = load(f)
1068
- except FileNotFoundError:
1069
- fix_json("File not found, repairing...")
1070
- except JSONDecodeError:
1071
- fix_json("JSON file format or content error")
1072
- else:
1073
- content_1 = data["test"]
1074
- content_2 = data["test2"]
1075
- color(f"Content 1: {content_1}\nContent 2: {content_2}\n\nTest successful!", 32, None, 1, 2)
1076
- remove(FILE_PATH)
1077
- ```
1
+ Metadata-Version: 2.4
2
+ Name: Luci-Code-Tools
3
+ Version: 2.3.0
4
+ Summary: 一个简单的工具库 / A Eazy Tools Module
5
+ Home-page: https://github.com/Luci-Code-2014
6
+ Author: Luci_Code
7
+ Author-email: luci90031@gmail.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: author
15
+ Dynamic: author-email
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: home-page
20
+ Dynamic: license-file
21
+ Dynamic: requires-python
22
+ Dynamic: summary
23
+
24
+ [![PyPI version](https://badge.fury.io/py/Luci\_Code_Tools.svg)](https://pypi.org/project/Luci\_Code_Tools/)
25
+
26
+ [![Python Version](https://img.shields.io/badge/Python-3.6+-blue.svg)]()
27
+
28
+ [![License](https://img.shields.io/badge/License-MIT-green.svg)]()
29
+
30
+ [![Cat](https://img.shields.io/badge/Cat-Approved-orange.svg)]()
31
+
32
+ ---
33
+
34
+ # 中文文档
35
+
36
+ **Chinese Document**
37
+
38
+ ---
39
+
40
+ **English Document use DeepSeek AI and Google Translate**
41
+
42
+ **There may be some inaccuracies**
43
+
44
+ ---
45
+
46
+ # 欢迎 💎
47
+
48
+ **感谢你点击这个项目**
49
+
50
+ **这是一个 *工具箱 / 快捷工具* 类型的项目**
51
+
52
+ **带有 *6* 个函数可使用**
53
+
54
+ # Luci\_Code_Tools 🔍
55
+
56
+ **代码花费 *9000+* 字符数**
57
+
58
+ ***2026 年 5 月 9 日*开始维护**
59
+
60
+ *26* 个异常处理, 个个定制的异常返回 **(触发异常时返回的操作)**
61
+
62
+ # 许可证 📄
63
+
64
+ 使用 **MIT License** 许可证
65
+
66
+ # 设备 📱 💻
67
+
68
+ 早期版本 (**2.1.5** 及更早) 使用 *Android* 上的 ***MT 管理器*** (软件开发者: **Bin**)
69
+
70
+ 早期版本以后的版本使用 (**版本 >=2.1.6**) ***Visual Studio Code*** 进行编写 (软件开发商: **Microsoft Corporation**)
71
+
72
+ ## 设备信息
73
+
74
+ Android 设备信息: Android 13
75
+
76
+ Windows 设备信息: Windows 10 22H2
77
+
78
+ # 作者 ヾ(≧▽≦*)o
79
+
80
+ 作者名字叫: **Luci\_Code**
81
+
82
+ **2014** 年出生 🐱
83
+
84
+ 此代码的编写者 : Luci\_Code
85
+
86
+ 此文档的编写者 : Luci\_Code
87
+
88
+ Github 链接: **https://github.com/Luci-Code-2014/**
89
+
90
+ ---
91
+
92
+ # 代码介绍 🎮
93
+
94
+ 项目文件夹 📂:
95
+
96
+ Luci\_Code_tools.py | 代码主文件
97
+
98
+ 200+ 行数运行的代码文件 🐱
99
+
100
+ setup.py | 上传信息
101
+
102
+ 在 PyPI 上上传时传输的信息
103
+
104
+ 包括 适用版本, 许可证信息等
105
+
106
+ 你可以在此模块的网页界面左边部分看到他给予的信息喵🐱
107
+
108
+ README.md | 此文档
109
+
110
+ 这就是你现在看到的文档喵🐱
111
+
112
+ LICENSE | 许可证 (MIT)
113
+
114
+ *MIT* 许可证是 目前 **(2026 年)** 最自由的许可证
115
+
116
+ 不要求你获得授权
117
+
118
+ 只要求在转载时能加一个来源喵🐱
119
+
120
+
121
+ ## 主代码
122
+
123
+ **26** 个异常处理
124
+
125
+ 包括:
126
+
127
+ *结果* 板块为代码中给出的结果
128
+
129
+ 在原本的代码中所有**异常处理**的结果都为报错
130
+
131
+ **错误退出**是指在错误的状态的报出错误并退出
132
+
133
+ 比如程序被不正确的方式报错了, 这时候就应该*错误退出*程序, 会被 SystemExit 捕获
134
+
135
+ | 报错 | 意思 | 结果 |
136
+ | --- | --- | --- |
137
+ | ValueError | 输入的值与期待的值类型错误 | 重试 |
138
+ | KeyboardInterrupt | 在 Ctrl + C 时, 命令行会被中断而显示的报错 | 退出 + 提示语 |
139
+ | EOFError | 意思是 End of file , 代表输入流被关闭 | 退出 + 提示语 |
140
+ | MemoryError | 内存过高导致的错误, 比如你输入了一个极高长度的字符超过了你的内存大小 | 退出(错误退出) + 提示语 |
141
+ | SystemError | Python 解释器损坏 | 退出 + 提示语 |
142
+ | OSError | 你系统炸了 😂 (可能是系统文件损坏问题引起的错误) | 退出(错误退出) + 提示语 |
143
+
144
+ 等错误, 总共有 **26** 种异常处理, 正常情况下 ***几乎不可能报错***
145
+
146
+ # 📦 安装方式 & 导入方式
147
+
148
+ ```bash
149
+ pip install Luci-Code-Tools
150
+ ```
151
+
152
+ 默认会安装最新版
153
+
154
+ 你可以通过把
155
+
156
+ ```bash
157
+ pip install <包名>
158
+ ```
159
+
160
+ 改成
161
+
162
+ ```bash
163
+ pip install <包名>==<版本号>
164
+ ```
165
+
166
+ 来安装对应的版本
167
+
168
+ ## 导入 & 引用
169
+
170
+ ```python
171
+
172
+ # 注: 所有方式的示例函数为 color 函数
173
+
174
+ # 导入
175
+ import Luci_Code_tools
176
+ Luci_Code_tools.color("HelloWorld", 32, None, 1, 2)
177
+
178
+ # 导入 + as
179
+ import Luci_Code_tools as lct
180
+ lct.color("HelloWorld", 32, None, 1, 2)
181
+
182
+ # 引用
183
+ from Luci_Code_tools import color
184
+ color("HelloWorld", 32, None, 1, 2)
185
+
186
+ # 引用 + as
187
+ from Luci_Code_tools import color as cl
188
+ cl("HelloWorld", 32, None, 1, 2)
189
+
190
+ ```
191
+
192
+ ---
193
+
194
+ # 参数介绍
195
+
196
+ line 的输出样式是
197
+
198
+ {
199
+
200
+ "line": 0,
201
+
202
+ "data": "Hello",
203
+
204
+ "data": "World",
205
+
206
+ "output": 2
207
+
208
+ } "output": 2 等于两个输出函数
209
+
210
+ 输出效果:
211
+
212
+ HelloWorld ("Hello" 和 "World" 是两个字符串)
213
+
214
+ {
215
+
216
+ "line": 1,
217
+
218
+ "data": "Hello",
219
+
220
+ "data": "World",
221
+
222
+ "output": 2
223
+
224
+ } "output": 2 等于两个输出函数
225
+
226
+ 输出效果:
227
+
228
+ Hello
229
+
230
+ (这里的空间其实不空行)
231
+
232
+ World
233
+
234
+ {
235
+
236
+ "line": 2,
237
+
238
+ "data": "Hello",
239
+
240
+ "data": "World",
241
+
242
+ "output": 2
243
+
244
+ } "output": 2 等于两个输出函数
245
+
246
+ 输出效果:
247
+
248
+ Hello
249
+
250
+ (Markdown 格式限制, 中间其实有空着一行)
251
+
252
+ World
253
+
254
+ line 参数可以调更高, 但是由于篇幅限制我需要减少测试喵🐱
255
+
256
+ 通过数字个性化调整空行数来提高辨识度
257
+
258
+ ## 函数参数
259
+
260
+ 我们先列出目前代码中所用的函数
261
+
262
+ ## 函数
263
+
264
+ - color_rgb
265
+
266
+ - color
267
+
268
+ - clear_screen
269
+
270
+ - safe_input
271
+
272
+ - safe_int
273
+
274
+ - safe_float
275
+
276
+ ## 所有参数
277
+
278
+ ---
279
+
280
+ 我们首先介绍 **color_rgb**
281
+
282
+ - color_rgb
283
+
284
+ 这个函数是一个管理 RGB 彩色输出的函数, 使用 **ANSI 转义序列 + 参数** 完成的构建
285
+
286
+ 参数包括:
287
+
288
+ data r g b mode line
289
+
290
+ - data
291
+
292
+ data 参数是控制 **输入的内容** 的参数
293
+
294
+ - r
295
+
296
+ - g
297
+
298
+ - b
299
+
300
+ 这三个参数按照 R, G, B 三个字符的顺序写, 比如 255, 0, 0 为**纯红色**
301
+
302
+ - mode
303
+
304
+ mode 参数是控制输出模式的参数, 具体输出模式参数表在最后
305
+
306
+ - line
307
+
308
+ line 参数输入整数, 具体信息在 **"参数介绍"** 部分片段
309
+
310
+ ---
311
+
312
+ - color
313
+
314
+ 此函数是一个管理 ANSI 转义序列彩色字符的函数 🤔
315
+
316
+ - data
317
+
318
+ 管理在彩色字符输出时输出的字符串
319
+
320
+ - text_color
321
+
322
+ 通过 ANSI 颜色码来控制输出的颜色, 不用调来调去, 详细参数在最后的参数表
323
+
324
+ - bg_color
325
+
326
+ 通过 ANSI 颜色码来控制输出时背景的颜色, 详细参数在最后的参数表
327
+
328
+ - mode
329
+
330
+ 通过 ANSI 转义序列的输出方式来控制输出 / 显示的方式
331
+
332
+ - line
333
+
334
+ 和上一位 color_rgb 是一个意思, 都可以控制输出时间隔的行数
335
+
336
+ ---
337
+
338
+ - clear_screen
339
+
340
+ clear_screen 没有参数, 但是我带来了函数介绍
341
+
342
+ **函数介绍**
343
+
344
+ 此函数有:
345
+
346
+ > 判断系统自动使用相对应清屏命令
347
+
348
+ 比如:
349
+
350
+ Android -> clear (Linux 内核)
351
+
352
+ Linux -> clear
353
+
354
+ Windows -> cls
355
+
356
+ 来切换使用的清屏命令
357
+
358
+ > 绝对的防注入, 列表控制清屏的参数与命令
359
+
360
+ > 即使是没有命令行的环境 (无法使用 clear / cls 命令的环境) 也可以使用 shutil 模块来检测终端高度并输出对应的空行数
361
+
362
+ > 甚至不能获取到终端高度也能输出 250 个空行来 "清屏"
363
+
364
+ ---
365
+
366
+ - safe_input
367
+
368
+ - safe_int
369
+
370
+ - safe_float
371
+
372
+ 这些 **safe_\*** 的参数都是一样的:
373
+
374
+ prompt | 提示词
375
+
376
+ text_color | 提示词颜色
377
+
378
+ bg_color | 提示词背景颜色
379
+
380
+ mode | 提示词输出方式
381
+
382
+ - prompt
383
+
384
+ prompt 跟 data 参数是一个意思喵🐱
385
+
386
+ - text_color
387
+
388
+ - bg_color
389
+
390
+ - mode
391
+
392
+ 这三个参数和 color, color_rgb 中的这三个参数是一样的, 代表的意思相同喵🐱
393
+
394
+ ---
395
+
396
+ # 参数表
397
+
398
+ ## 前景色
399
+
400
+ | 前景色 - 值 | 效果 |
401
+ | --- | --- |
402
+ | 30 | 黑色 |
403
+ | 31 | 红色 |
404
+ | 32 | 绿色 |
405
+ | 33 | 黄色 |
406
+ | 34 | 蓝色 |
407
+ | 35 | 紫色 |
408
+ | 36 | 青色 |
409
+ | 37 | 白色 |
410
+
411
+ ## 前景色 - 浅色
412
+
413
+ | 前景色 - 值 | 效果 |
414
+ | --- | --- |
415
+ | 90 | 深灰色 |
416
+ | 91 | 浅红色 |
417
+ | 92 | 浅绿色 |
418
+ | 93 | 浅黄色 |
419
+ | 94 | 浅蓝色 |
420
+ | 95 | 浅紫色 |
421
+ | 96 | 浅青色 |
422
+ | 97 | 浅灰色 |
423
+
424
+ ## 背景色
425
+
426
+ | 背景色 - 值 | 效果 |
427
+ | --- | --- |
428
+ | 40 | 黑色 |
429
+ | 41 | 红色 |
430
+ | 42 | 绿色 |
431
+ | 43 | 黄色 |
432
+ | 44 | 蓝色 |
433
+ | 45 | 紫色 |
434
+ | 46 | 青色 |
435
+ | 47 | 白色 |
436
+
437
+ ## 背景色 - 浅色
438
+
439
+ | 背景色 - 值 | 效果 |
440
+ | --- | --- |
441
+ | 100 | 深灰色 |
442
+ | 101 | 浅红色 |
443
+ | 102 | 浅绿色 |
444
+ | 103 | 浅黄色 |
445
+ | 104 | 浅蓝色 |
446
+ | 105 | 浅紫色 |
447
+ | 106 | 浅青色 |
448
+ | 107 | 纯白色 |
449
+
450
+ ## 输出方式
451
+
452
+ | 显示方式 - 值 | 效果 |
453
+ | --- | --- |
454
+ | 0 | 默认 |
455
+ | 1 | 高亮 + 加粗 |
456
+ | 2 | 暗淡 |
457
+ | 3 | 斜体 (部分终端可能不支持) |
458
+ | 4 | 下划线 |
459
+ | 5 | 闪烁 |
460
+ | 6 | 快闪(部分终端可能不支持) |
461
+ | 7 | 反色(前景色与背景色互换) |
462
+ | 8 | 隐藏 |
463
+ | 9 | 删除线 |
464
+
465
+ ---
466
+
467
+ # 制作人员 & 感谢名单 (以贡献程度排名从上到下)
468
+
469
+ | 人员 | 提供 |
470
+ | --- | --- |
471
+ | DeepSeek | 构建 & 打包 & 上传教程 |
472
+ | DeepSeek | 提供改进意见 |
473
+ | DeepSeek | 环境帮助 |
474
+ | Luci\_Code | 编写 |
475
+ | Luci\_Code | 打包 |
476
+ | Luci\_Code | 制作 |
477
+ | Luci\_Code | 构建 |
478
+ | Luci\_Code | 上传 |
479
+ | Luci\_Code | 构思 |
480
+
481
+ ---
482
+
483
+ # 快速上手
484
+
485
+ ## 输入输出
486
+
487
+ ```python
488
+ from Luci_Code_tools import color, safe_input
489
+
490
+ text = safe_input("请输入文本: ", 32, None, 1)
491
+ color(f"你输入了 {text}", 32, None, 1, 2)
492
+ ```
493
+
494
+ ## 计算器
495
+
496
+ ```python
497
+ from Luci_Code_tools import color, safe_float, safe_input
498
+ from sys import exit
499
+
500
+ color("=== 计算器 ===", 32, None, 1, 2)
501
+ while True:
502
+ num1 = safe_float("请输入第一位数字: ", 32, None, 1)
503
+ num2 = safe_float("请输入第二位数字: ", 32, None, 1)
504
+ operators = safe_input("请输入运算符(+, -, *, /, 输入 quit 退出): ")
505
+ if operators == "+":
506
+ color(f"结果为: {num1 + num2}\n==========", 32, None, 1, 2)
507
+ continue
508
+ elif operators == "-":
509
+ color(f"结果为: {num1 - num2}\n==========", 32, None, 1, 2)
510
+ continue
511
+ elif operators == "*":
512
+ color(f"结果为: {num1 * num2}\n==========", 32, None, 1, 2)
513
+ continue
514
+ elif operators == "/":
515
+ if num2 == 0:
516
+ color("除数不能等于 0\n==========", 33, None, 1, 2)
517
+ continue
518
+ else:
519
+ color(f"结果为: {num1 / num2}\n==========", 32, None, 1, 2)
520
+ continue
521
+ elif operators == "quit":
522
+ color("=== 退出成功 ===", 32, None, 1, 2)
523
+ exit(0)
524
+ else:
525
+ color("没有这个运算符!\n==========", 33, None, 1, 2)
526
+ continue
527
+ ```
528
+
529
+ ## 文件读写
530
+
531
+ ```python
532
+ from Luci_Code_tools import color
533
+ from os import remove
534
+ from json import load, dump, JSONDecodeError
535
+
536
+ JSON = {
537
+ "test": "This is Test content",
538
+ "test2": "This is Test content 2"
539
+ }
540
+
541
+ FILE_PATH = "user.json"
542
+
543
+ def fix_json(prompt: str) -> None:
544
+ color(prompt, 33, None, 1, 2)
545
+ with open(FILE_PATH, "w", encoding="utf-8") as f:
546
+ dump(JSON, f, ensure_ascii=False, indent=4, sort_keys=True)
547
+ color("修复成功! 请重启程序", 32, None, 1)
548
+
549
+ try:
550
+ with open(FILE_PATH, "r", encoding="utf-8") as f:
551
+ data = load(f)
552
+ except FileNotFoundError:
553
+ fix_json("文件不存在, 正在修复中...")
554
+ except JSONDecodeError:
555
+ fix_json("Json 文件格式或内容错误")
556
+ else:
557
+ content_1 = data["test"]
558
+ content_2 = data["test2"]
559
+ color(f"内容1: {content_1}\n内容2: {content_2}\n\n测试成功!", 32, None, 1, 2)
560
+ remove(FILE_PATH)
561
+ ```
562
+
563
+ ---
564
+
565
+ # English Document
566
+
567
+ **英语文档**
568
+
569
+ ---
570
+
571
+ # Welcome 💎
572
+
573
+ **Thanks for checking out this project**
574
+
575
+ **This is a *toolbox / quick-utility* style project**
576
+
577
+ **Features *6* functions for use**
578
+
579
+ # Luci\_Code_Tools 🔍
580
+
581
+ **Codebase spans over *9,000* characters**
582
+
583
+ **Maintenance began on *May 9, 2026***
584
+
585
+ *26* exception handlers, each with a custom return value **(the output returned when an exception is triggered)**
586
+
587
+ # License 📄
588
+
589
+ Uses the **MIT License**
590
+
591
+ # Devices 📱 💻
592
+
593
+ Early versions (**2.1.5** and earlier) were developed using ***MT Manager*** on *Android* (Developer: **Bin**)
594
+
595
+ Versions from **2.1.6** onwards were written using ***Visual Studio Code*** (Developer: **Microsoft Corporation**)
596
+
597
+ ## Device Information
598
+
599
+ Android device info: Android 13
600
+
601
+ Windows device info: Windows 10 22H2
602
+
603
+ # Author ヾ(≧▽≦*)o
604
+
605
+ Author's name: **Luci\_Code**
606
+
607
+ Born in **2014** 🐱
608
+
609
+ Code written by: Luci\_Code
610
+
611
+ Documentation written by: Luci\_Code
612
+
613
+ GitHub link: **https://github.com/Luci-Code-2014/**
614
+
615
+ ---
616
+
617
+ # Code Overview 🎮
618
+
619
+ Project folders/files 📂:
620
+
621
+ Luci\_Code_tools.py | Main code file
622
+
623
+ A script spanning over 200 lines of code 🐱
624
+
625
+ setup.py | Upload metadata
626
+
627
+ Information transmitted during PyPI upload
628
+
629
+ Includes compatible versions, license details, etc.
630
+
631
+ You can view this information on the left side of the module's webpage 🐱
632
+
633
+ README.md | This document
634
+
635
+ The very document you are reading right now 🐱
636
+
637
+ LICENSE | License (MIT)
638
+
639
+ The *MIT* License is currently **(as of 2026)** the most permissive license available
640
+
641
+ It does not require you to obtain explicit authorization
642
+
643
+ It only asks that you credit the source when redistributing 🐱
644
+
645
+ ## Main Code
646
+
647
+ **26** exception handlers
648
+
649
+ Including:
650
+
651
+ *Results* The sections below describe the results defined in the code.
652
+
653
+ In the original code, all **exception handling** scenarios result in an error report.
654
+
655
+ **Error Exit** refers to raising an error due to an invalid state and subsequently terminating the program.
656
+
657
+ For instance, if the program encounters an improper error condition, it should perform an *Error Exit*; this is caught by `SystemExit`.
658
+
659
+ | Error | Meaning | Result |
660
+ | --- | --- | --- |
661
+ | ValueError | Input value type does not match expected type | Retry |
662
+ | KeyboardInterrupt | Error displayed when the command line is interrupted (e.g., Ctrl + C) | Exit + Message |
663
+ | EOFError | End of File; indicates the input stream has been closed | Exit + Message |
664
+ | MemoryError | Error caused by excessive memory usage (e.g., inputting a string exceeding available memory) | Exit (Error Exit) + Message |
665
+ | SystemError | Python interpreter corruption | Exit + Message |
666
+ | OSError | Your system crashed 😂 (likely caused by corrupted system files) | Exit (Error Exit) + Message |
667
+
668
+ There are **26** types of exception handling in total; under normal circumstances, errors ***almost never occur***.
669
+
670
+ # 📦 Installation & Import
671
+
672
+ ```bash
673
+ pip install Luci-Code-Tools
674
+ ```
675
+
676
+ This installs the latest version by default.
677
+
678
+ You can install a specific version by changing
679
+
680
+ ```bash
681
+ pip install <package_name>
682
+ ```
683
+
684
+ to
685
+
686
+ ```bash
687
+ pip install <package_name>==<version_number>
688
+ ```
689
+
690
+ ## Import & Reference
691
+
692
+ ```python
693
+
694
+ # Note: The example function used in all cases is the 'color' function
695
+
696
+ # Import
697
+ import Luci_Code_tools
698
+ Luci_Code_tools.color("HelloWorld", 32, None, 1, 2)
699
+
700
+ # Import + as
701
+ import Luci_Code_tools as lct
702
+ lct.color("HelloWorld", 32, None, 1, 2)
703
+
704
+ # Reference
705
+ from Luci_Code_tools import color
706
+ color("HelloWorld", 32, None, 1, 2)
707
+
708
+ # Reference + as
709
+ from Luci_Code_tools import color as cl
710
+ cl("HelloWorld", 32, None, 1, 2)
711
+
712
+ ```
713
+
714
+ ---
715
+
716
+ # Parameter Introduction
717
+
718
+ The output style for `line` is:
719
+
720
+ ```json
721
+ {
722
+ "line": 0,
723
+ "data": "Hello",
724
+ "data": "World",
725
+ "output": 2
726
+ }
727
+ ```
728
+ `"output": 2` corresponds to two output functions.
729
+
730
+ Output effect:
731
+
732
+ HelloWorld ("Hello" and "World" are two separate strings)
733
+
734
+ ```json
735
+ {
736
+ "line": 1,
737
+ "data": "Hello",
738
+ "data": "World",
739
+ "output": 2
740
+ }
741
+ ```
742
+ `"output": 2` corresponds to two output functions.
743
+
744
+ Output effect:
745
+
746
+ Hello
747
+
748
+ (There is actually no blank line here)
749
+
750
+ World
751
+
752
+ ```json
753
+ {
754
+ "line": 2,
755
+ "data": "Hello",
756
+ "data": "World",
757
+ "output": 2
758
+ }
759
+ ```
760
+ `"output": 2` corresponds to two output functions.
761
+
762
+ Output effect:
763
+
764
+ Hello
765
+
766
+ (There is actually a blank line in between)
767
+
768
+ World
769
+
770
+ The `line` parameter can be set higher, but I need to limit the number of tests due to space constraints 🐱
771
+
772
+ Adjust the number of blank lines numerically to improve readability.
773
+
774
+ ## Function Parameters
775
+
776
+ Let's first list the functions currently used in the code.
777
+
778
+ ## Functions
779
+
780
+ - color_rgb
781
+
782
+ - color
783
+
784
+ - clear_screen
785
+
786
+ - safe_input
787
+
788
+ - safe_int
789
+
790
+ - safe_float
791
+
792
+ ## All Parameters
793
+
794
+ ---
795
+
796
+ First, let's introduce **color_rgb**
797
+
798
+ - color_rgb
799
+
800
+ This function manages RGB color output; it is constructed using **ANSI escape sequences + parameters**.
801
+
802
+ Parameters include:
803
+
804
+ data r g b mode line
805
+
806
+ - data
807
+
808
+ The `data` parameter controls the **content to be output**.
809
+
810
+ - r
811
+
812
+ - g
813
+
814
+ - b
815
+
816
+ These three parameters are specified in the order of R, G, and B; for example, `255, 0, 0` represents **pure red**.
817
+
818
+ - mode
819
+
820
+ The `mode` parameter controls the output mode; a table of specific output modes is provided at the end.
821
+
822
+ - line
823
+
824
+ The `line` parameter accepts an integer; specific details can be found in the **"Parameter Introduction"** section above.
825
+
826
+ ---
827
+
828
+ - color
829
+
830
+ This function manages colored text using ANSI escape sequences 🤔
831
+
832
+ - data
833
+
834
+ Manages the string to be output with color formatting.
835
+
836
+ - text_color
837
+
838
+ Controls the output color using ANSI color codes; no need for complex adjustments. Detailed parameters are in the parameter table at the end.
839
+
840
+ - bg_color
841
+
842
+ Controls the background color of the output using ANSI color codes. Detailed parameters are in the parameter table at the end.
843
+
844
+ - mode
845
+
846
+ Controls the output/display style using ANSI escape sequences.
847
+
848
+ - line
849
+
850
+ Serves the same purpose as the `color_rgb` parameter mentioned earlier; both control the number of blank lines between outputs.
851
+
852
+ ---
853
+
854
+ - clear_screen
855
+
856
+ `clear_screen` takes no arguments, but here is an introduction to the function.
857
+
858
+ **Function Introduction**
859
+
860
+ This function:
861
+
862
+ > Automatically detects the system and uses the corresponding screen-clearing command.
863
+
864
+ For example:
865
+
866
+ Android -> `clear` (Linux kernel)
867
+
868
+ Linux -> `clear`
869
+
870
+ Windows -> `cls`
871
+
872
+ It switches the command used based on the OS.
873
+
874
+ > Ensures absolute protection against injection attacks by using a controlled list of parameters and commands for clearing the screen.
875
+
876
+ > Can use the `shutil` module to detect terminal height and output the appropriate number of blank lines, even in environments without a command-line interface (where `clear` or `cls` commands are unavailable).
877
+
878
+ > Can output 250 blank lines to "clear the screen" even if the terminal height cannot be detected.
879
+
880
+ ---
881
+
882
+ - safe_input
883
+
884
+ - safe_int
885
+
886
+ - safe_float
887
+
888
+ These `safe_*` functions share the same parameters:
889
+
890
+ prompt | Prompt text
891
+
892
+ text_color | Prompt text color
893
+
894
+ bg_color | Prompt background color
895
+
896
+ mode | Prompt output style
897
+
898
+ - prompt
899
+
900
+ The `prompt` parameter serves the same purpose as the `data` parameter.
901
+
902
+ - text_color
903
+
904
+ - bg_color
905
+
906
+ - mode
907
+
908
+ These three parameters are identical to the corresponding ones in `color` and `color_rgb`, serving the same function.
909
+
910
+ ---
911
+
912
+ # Parameter Table
913
+
914
+ ## Foreground Color
915
+
916
+ | Foreground Color - Value | Effect |
917
+ | --- | --- |
918
+ | 30 | Black |
919
+ | 31 | Red |
920
+ | 32 | Green |
921
+ | 33 | Yellow |
922
+ | 34 | Blue |
923
+ | 35 | Purple |
924
+ | 36 | Cyan |
925
+ | 37 | White |
926
+
927
+ ## Foreground Color - Light/Bright
928
+
929
+ | Foreground Color - Value | Effect |
930
+ | --- | --- |
931
+ | 90 | Dark gray |
932
+ | 91 | Light red |
933
+ | 92 | Light green |
934
+ | 93 | Light yellow |
935
+ | 94 | Light blue |
936
+ | 95 | Light purple |
937
+ | 96 | Light cyan |
938
+ | 97 | Light gray |
939
+
940
+ ## Background Color
941
+
942
+ | Background Color - Value | Effect |
943
+ | --- | --- |
944
+ | 40 | Black |
945
+ | 41 | Red |
946
+ | 42 | Green |
947
+ | 43 | Yellow |
948
+ | 44 | Blue |
949
+ | 45 | Purple |
950
+ | 46 | Cyan |
951
+ | 47 | White |
952
+
953
+ ## Background Color - Light Shades
954
+
955
+ | Background Color - Value | Effect |
956
+ | --- | --- |
957
+ | 100 | Dark gray |
958
+ | 101 | Light red |
959
+ | 102 | Light green |
960
+ | 103 | Light yellow |
961
+ | 104 | Light blue |
962
+ | 105 | Light purple |
963
+ | 106 | Light cyan |
964
+ | 107 | Pure white |
965
+
966
+ ## Output Mode
967
+
968
+ | Display Mode - Value | Effect |
969
+ | --- | --- |
970
+ | 0 | Default |
971
+ | 1 | Highlight + Bold |
972
+ | 2 | Dim |
973
+ | 3 | Italic (may not be supported by some terminals) |
974
+ | 4 | Underline |
975
+ | 5 | Blink |
976
+ | 6 | Rapid blink (may not be supported by some terminals) |
977
+ | 7 | Invert (swap foreground and background colors) |
978
+ | 8 | Hidden |
979
+ | 9 | Strikethrough |
980
+
981
+ ---
982
+
983
+ # Credits & Acknowledgments (Ranked by contribution level, top to bottom)
984
+
985
+ | Person/Entity | Contribution |
986
+ | --- | --- |
987
+ | DeepSeek | Build, packaging, and upload tutorial |
988
+ | DeepSeek | Provided improvement suggestions |
989
+ | DeepSeek | Environment help |
990
+ | Luci\_Code | Writing |
991
+ | Luci\_Code | Packaging |
992
+ | Luci\_Code | Creation |
993
+ | Luci\_Code | Building |
994
+ | Luci\_Code | Uploading |
995
+ | Luci\_Code | Conceptualization |
996
+
997
+ ---
998
+
999
+ # Quick Start
1000
+
1001
+ ## Input and Output
1002
+
1003
+ ```python
1004
+ from Luci_Code_tools import color, safe_input
1005
+
1006
+ text = safe_input("Please enter text: ", 32, None, 1)
1007
+ color(f"You entered {text}", 32, None, 1, 2)
1008
+ ```
1009
+
1010
+ ## Calculator
1011
+
1012
+ ```python
1013
+ from Luci_Code_tools import color, safe_float, safe_input
1014
+ from sys import exit
1015
+
1016
+ color("=== Calculator ===", 32, None, 1, 2)
1017
+ while True:
1018
+ num1 = safe_float("Enter the first number: ", 32, None, 1)
1019
+ num2 = safe_float("Enter the second number: ", 32, None, 1)
1020
+ operators = safe_input("Enter operator (+, -, *, /, type 'quit' to exit): ")
1021
+ if operators == "+":
1022
+ color(f"Result: {num1 + num2}\n==========", 32, None, 1, 2)
1023
+ continue
1024
+ elif operators == "-":
1025
+ color(f"Result: {num1 - num2}\n==========", 32, None, 1, 2)
1026
+ continue
1027
+ elif operators == "*":
1028
+ color(f"Result: {num1 * num2}\n==========", 32, None, 1, 2)
1029
+ continue
1030
+ elif operators == "/":
1031
+ if num2 == 0:
1032
+ color("Divisor cannot be zero\n==========", 33, None, 1, 2)
1033
+ continue
1034
+ else:
1035
+ color(f"Result: {num1 / num2}\n==========", 32, None, 1, 2)
1036
+ continue
1037
+ elif operators == "quit":
1038
+ color("=== Exit successful ===", 32, None, 1, 2)
1039
+ exit(0)
1040
+ else:
1041
+ color("Invalid operator!\n==========", 33, None, 1, 2)
1042
+ continue
1043
+ ```
1044
+
1045
+ ## File Read and Write
1046
+
1047
+ ```python
1048
+ from Luci_Code_tools import color
1049
+ from os import remove
1050
+ from json import load, dump, JSONDecodeError
1051
+
1052
+ JSON = {
1053
+ "test": "This is Test content",
1054
+ "test2": "This is Test content 2"
1055
+ }
1056
+
1057
+ FILE_PATH = "user.json"
1058
+
1059
+ def fix_json(prompt: str) -> None:
1060
+ color(prompt, 33, None, 1, 2)
1061
+ with open(FILE_PATH, "w", encoding="utf-8") as f:
1062
+ dump(JSON, f, ensure_ascii=False, indent=4, sort_keys=True)
1063
+ color("Repair successful! Please restart the program", 32, None, 1)
1064
+
1065
+ try:
1066
+ with open(FILE_PATH, "r", encoding="utf-8") as f:
1067
+ data = load(f)
1068
+ except FileNotFoundError:
1069
+ fix_json("File not found, repairing...")
1070
+ except JSONDecodeError:
1071
+ fix_json("JSON file format or content error")
1072
+ else:
1073
+ content_1 = data["test"]
1074
+ content_2 = data["test2"]
1075
+ color(f"Content 1: {content_1}\nContent 2: {content_2}\n\nTest successful!", 32, None, 1, 2)
1076
+ remove(FILE_PATH)
1077
+ ```