Metadata-Version: 2.4
Name: Luci-Code-Tools
Version: 2.2.9
Summary: 一个简单的工具库 / A Eazy Tools Module
Home-page: https://github.com/Luci-Code-2014
Author: Luci_Code
Author-email: 3967742419@qq.com
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python
Dynamic: summary

[![PyPI version](https://badge.fury.io/py/Luci\_Code_Tools.svg)](https://pypi.org/project/Luci\_Code_Tools/)

[![Python Version](https://img.shields.io/badge/Python-3.6+-blue.svg)]()

[![License](https://img.shields.io/badge/License-MIT-green.svg)]()

[![Cat](https://img.shields.io/badge/Cat-Approved-orange.svg)]()

---

# 中文文档

**Chinese Document**

---

**English Document use DeepSeek AI and Google Translate**

**There may be some inaccuracies**

---

# 欢迎 💎

**感谢你点击这个项目**

**这是一个 *工具箱 / 快捷工具* 类型的项目**

**带有 *6* 个函数可使用**

# Luci\_Code_Tools 🔍

**代码花费 *9000+* 字符数**

***2026 年 5 月 9 日*开始维护**

*27* 个异常处理, 个个定制的异常返回 **(触发异常时返回的操作)**

# 许可证 📄

使用 **MIT License** 许可证

# 设备 📱 💻

早期版本 (**2.1.5** 及更早) 使用 *Android* 上的 ***MT 管理器*** (软件开发者: **Bin**)

早期版本以后的版本使用 (**版本 >=2.1.6**) ***Visual Studio Code*** 进行编写 (软件开发商: **Microsoft Corporation**)

## 设备信息

Android 设备信息: Android 13 

Windows 设备信息: Windows 10 22H2

# 作者 ヾ(≧▽≦*)o

作者名字叫: **Luci\_Code**

**2014** 年出生 🐱

此代码的编写者 : Luci\_Code

此文档的编写者 : Luci\_Code

Github 链接: **https://github.com/Luci-Code-2014/**

---

# 代码介绍 🎮

项目文件夹 📂:

Luci\_Code_tools.py | 代码主文件

200+ 行数运行的代码文件 🐱

setup.py | 上传信息

在 PyPI 上上传时传输的信息

包括 适用版本, 许可证信息等

你可以在此模块的网页界面左边部分看到他给予的信息喵🐱

README.md | 此文档

这就是你现在看到的文档喵🐱

LICENSE | 许可证 (MIT)

*MIT* 许可证是 目前 **(2026 年)** 最自由的许可证

他不要求你获得授权

他只要求在转载时能加一个来源喵🐱


## 主代码

**27** 个异常处理

包括:

*结果* 板块为代码中给出的结果

在原本的代码中所有**异常处理**的结果都为报错

**错误退出**是指在错误的状态的报出错误并退出

比如程序被不正确的方式报错了, 这时候就应该*错误退出*程序, 会被 SystemExit 捕获

| 报错 | 意思 | 结果 |
| --- | --- | --- |
| ValueError | 输入的值与期待的值类型错误 | 重试 |
| KeyboardInterrupt | 在 Ctrl + C 时, 命令行会被中断而显示的报错 | 退出 + 提示语 |
| EOFError | 意思是 End of file , 代表输入流被关闭 | 退出 + 提示语 |
| MemoryError | 内存过高导致的错误, 比如你输入了一个极高长度的字符超过了你的内存大小 | 退出(错误退出) + 提示语 |
| SystemError | Python 解释器损坏 | 退出 + 提示语 |
| OSError | 你系统炸了 😂 (可能是系统文件损坏问题引起的错误) | 退出(错误退出) + 提示语 |

等错误, 总共有 **27** 种异常处理, 正常情况下 ***几乎不可能报错***

# 📦 安装方式 & 导入方式

```bash
pip install Luci-Code-Tools
```

默认会安装最新版

你可以通过把

```bash
pip install <包名>
```

改成

```bash
pip install <包名>==<版本号>
```

来安装对应的版本

## 导入 & 引用

```python

# 注: 所有方式的示例函数为 color 函数

# 导入
import Luci_Code_tools
Luci_Code_tools.color("HelloWorld", 32, None, 1, 2)

# 导入 + as
import Luci_Code_tools as lct
lct.color("HelloWorld", 32, None, 1, 2)

# 引用
from Luci_Code_tools import color
color("HelloWorld", 32, None, 1, 2)

# 引用 + as
from Luci_Code_tools import color as cl
cl("HelloWorld", 32, None, 1, 2)

```

---

# 参数介绍

line 的输出样式是

{

    "line": 0,

    "data": "Hello",

    "data": "World",

    "output": 2

} "output": 2 等于两个输出函数

输出效果:

HelloWorld ("Hello" 和 "World" 是两个字符串)

{

    "line": 1,

    "data": "Hello",

    "data": "World",

    "output": 2

} "output": 2 等于两个输出函数

输出效果:

Hello

(这里的空间其实不空行)

World

{

    "line": 2,

    "data": "Hello",

    "data": "World",

    "output": 2

} "output": 2 等于两个输出函数

输出效果:

Hello

(Markdown 格式限制, 中间其实有空着一行)

World

line 参数可以调更高, 但是由于篇幅限制我需要减少测试喵🐱

通过数字个性化调整空行数来提高辨识度

## 函数参数

我们先列出目前代码中所用的函数

## 函数

- color_rgb

- color

- clear_screen

- safe_input

- safe_int

- safe_float

## 所有参数

---                                                                                        

我们首先介绍 **color_rgb**

- color_rgb

这个函数是一个管理 RGB 彩色输出的函数, 使用 **ANSI 转义序列 + 参数** 完成的构建

参数包括:

data r g b mode line

- data

data 参数是控制 **输入的内容** 的参数

- r

- g

- b

这三个参数按照 R, G, B 三个字符的顺序写, 比如 255, 0, 0 为**纯红色**

- mode

mode 参数是控制输出模式的参数, 具体输出模式参数表在最后

- line

line 参数输入整数, 具体信息在 **"参数介绍"** 部分片段

---

- color

此函数是一个管理 ANSI 转义序列彩色字符的函数 🤔

- data

管理在彩色字符输出时输出的字符串

- text_color

通过 ANSI 颜色码来控制输出的颜色, 不用调来调去, 详细参数在最后的参数表

- bg_color

通过 ANSI 颜色码来控制输出时背景的颜色, 详细参数在最后的参数表

- mode

通过 ANSI 转义序列的输出方式来控制输出 / 显示的方式

- line

和上一位 color_rgb 是一个意思, 都可以控制输出时间隔的行数

---

- clear_screen

clear_screen 没有参数, 但是我带来了函数介绍

**函数介绍**

此函数有:

> 判断系统自动使用相对应清屏命令

比如:

Android -> clear (Linux 内核)

Linux -> clear

Windows -> cls

来切换使用的清屏命令

> 绝对的防注入, 列表控制清屏的参数与命令

> 即使是没有命令行的环境 (无法使用 clear / cls 命令的环境) 也可以使用 shutil 模块来检测终端高度并输出对应的空行数

> 甚至不能获取到终端高度也能输出 250 个空行来 "清屏"

---

- safe_input

- safe_int

- safe_float

这些 **safe_\*** 的参数都是一样的:

prompt | 提示词

text_color | 提示词颜色

bg_color | 提示词背景颜色

mode | 提示词输出方式

- prompt

prompt 跟 data 参数是一个意思喵🐱

- text_color

- bg_color

- mode

这三个参数和 color, color_rgb 中的这三个参数是一样的, 代表的意思相同喵🐱

---

# 参数表

## 前景色

| 前景色 - 值 | 效果 |
| --- | --- |
| 30 | 黑色 |
| 31 | 红色 |
| 32 | 绿色 |
| 33 | 黄色 |
| 34 | 蓝色 |
| 35 | 紫色 |
| 36 | 青色 |
| 37 | 白色 |

## 前景色 - 浅色

| 前景色 - 值 | 效果 |
| --- | --- |
| 90 | 深灰色 |
| 91 | 浅红色 |
| 92 | 浅绿色 |
| 93 | 浅黄色 |
| 94 | 浅蓝色 |
| 95 | 浅紫色 |
| 96 | 浅青色 |
| 97 | 浅灰色 |

## 背景色

| 背景色 - 值 | 效果 |
| --- | --- |
| 40 | 黑色 |
| 41 | 红色 |
| 42 | 绿色 |
| 43 | 黄色 |
| 44 | 蓝色 |
| 45 | 紫色 |
| 46 | 青色 |
| 47 | 白色 |

## 背景色 - 浅色

| 背景色 - 值 | 效果 |
| --- | --- |
| 100 | 深灰色 |
| 101 | 浅红色 |
| 102 | 浅绿色 |
| 103 | 浅黄色 |
| 104 | 浅蓝色 |
| 105 | 浅紫色 |
| 106 | 浅青色 |
| 107 | 纯白色 |

## 输出方式

| 显示方式 - 值 | 效果 |
| --- | --- |
| 0 | 默认 |
| 1 | 高亮 + 加粗 |
| 2 | 暗淡 |
| 3 | 斜体 (部分终端可能不支持) |
| 4 | 下划线 |
| 5 | 闪烁 |
| 6 | 快闪(部分终端可能不支持) |
| 7 | 反色(前景色与背景色互换) |
| 8 | 隐藏 |
| 9 | 删除线 |

---

# 制作人员 & 感谢名单 (以贡献程度排名从上到下)

| 人员 | 提供 |
| --- | --- |
| DeepSeek | 构建 & 打包 & 上传教程 |
| DeepSeek | 提供改进意见 |
| DeepSeek | 环境帮助 |
| Luci\_Code | 编写 |
| Luci\_Code | 打包 |
| Luci\_Code | 制作 |
| Luci\_Code | 构建 |
| Luci\_Code | 上传 |
| Luci\_Code | 构思 |

---

# 快速上手

## 输入输出

```python
from Luci_Code_tools import color, safe_input

text = safe_input("请输入文本: ", 32, None, 1)
color(f"你输入了 {text}", 32, None, 1, 2)
```

## 计算器

```python
from Luci_Code_tools import color, safe_float, safe_input
from sys import exit

color("=== 计算器 ===", 32, None, 1, 2)
while True:
    num1 = safe_float("请输入第一位数字: ", 32, None, 1)
    num2 = safe_float("请输入第二位数字: ", 32, None, 1)
    operators = safe_input("请输入运算符(+, -, *, /, 输入 quit 退出): ")
    if operators == "+":
        color(f"结果为: {num1 + num2}\n==========", 32, None, 1, 2)
        continue
    elif operators == "-":
        color(f"结果为: {num1 - num2}\n==========", 32, None, 1, 2)
        continue
    elif operators == "*":
        color(f"结果为: {num1 * num2}\n==========", 32, None, 1, 2)
        continue
    elif operators == "/":
        if num2 == 0:
            color("除数不能等于 0\n==========", 33, None, 1, 2)
            continue
        else:
            color(f"结果为: {num1 / num2}\n==========", 32, None, 1, 2)
            continue
    elif operators == "quit":
        color("=== 退出成功 ===", 32, None, 1, 2)
        exit(0)
    else:
        color("没有这个运算符!\n==========", 33, None, 1, 2)
        continue
```

## 文件读写

```python
from Luci_Code_tools import color
from os import remove
from json import load, dump, JSONDecodeError

JSON = {
    "test": "This is Test content",
    "test2": "This is Test content 2"
}

FILE_PATH = "user.json"

def fix_json(prompt: str) -> None:
    color(prompt, 33, None, 1, 2)
    with open(FILE_PATH, "w", encoding="utf-8") as f:
        dump(JSON, f, ensure_ascii=False, indent=4, sort_keys=True)
    color("修复成功! 请重启程序", 32, None, 1)

try:
    with open(FILE_PATH, "r", encoding="utf-8") as f:
        data = load(f)
except FileNotFoundError:
    fix_json("文件不存在, 正在修复中...")
except JSONDecodeError:
    fix_json("Json 文件格式或内容错误")
else:
    content_1 = data["test"]
    content_2 = data["test2"]
    color(f"内容1: {content_1}\n内容2: {content_2}\n\n测试成功!", 32, None, 1, 2)
    remove(FILE_PATH)
```

---

# English Document

**英语文档**

---

# Welcome 💎

**Thanks for checking out this project**

**This is a *toolbox / quick-utility* style project**

**Features *6* functions for use**

# Luci\_Code_Tools 🔍

**Codebase spans over *9,000* characters**

**Maintenance began on *May 9, 2026***

*27* exception handlers, each with a custom return value **(the output returned when an exception is triggered)**

# License 📄

Uses the **MIT License**

# Devices 📱 💻

Early versions (**2.1.5** and earlier) were developed using ***MT Manager*** on *Android* (Developer: **Bin**)

Versions from **2.1.6** onwards were written using ***Visual Studio Code*** (Developer: **Microsoft Corporation**)

## Device Information

Android device info: Android 13

Windows device info: Windows 10 22H2

# Author ヾ(≧▽≦*)o

Author's name: **Luci\_Code**

Born in **2014** 🐱

Code written by: Luci\_Code

Documentation written by: Luci\_Code

GitHub link: **https://github.com/Luci-Code-2014/**

---

# Code Overview 🎮

Project folders/files 📂:

Luci\_Code_tools.py | Main code file

A script spanning over 200 lines of code 🐱

setup.py | Upload metadata

Information transmitted during PyPI upload

Includes compatible versions, license details, etc.

You can view this information on the left side of the module's webpage 🐱

README.md | This document

The very document you are reading right now 🐱

LICENSE | License (MIT)

The *MIT* License is currently **(as of 2026)** the most permissive license available

It does not require you to obtain explicit authorization

It only asks that you credit the source when redistributing 🐱

## Main Code

**27** exception handlers

Including:

*Results* The sections below describe the results defined in the code.

In the original code, all **exception handling** scenarios result in an error report.

**Error Exit** refers to raising an error due to an invalid state and subsequently terminating the program.

For instance, if the program encounters an improper error condition, it should perform an *Error Exit*; this is caught by `SystemExit`.

| Error | Meaning | Result |
| --- | --- | --- |
| ValueError | Input value type does not match expected type | Retry |
| KeyboardInterrupt | Error displayed when the command line is interrupted (e.g., Ctrl + C) | Exit + Message |
| EOFError | End of File; indicates the input stream has been closed | Exit + Message |
| MemoryError | Error caused by excessive memory usage (e.g., inputting a string exceeding available memory) | Exit (Error Exit) + Message |
| SystemError | Python interpreter corruption | Exit + Message |
| OSError | Your system crashed 😂 (likely caused by corrupted system files) | Exit (Error Exit) + Message |

There are **27** types of exception handling in total; under normal circumstances, errors ***almost never occur***.

# 📦 Installation & Import

```bash
pip install Luci-Code-Tools
```

This installs the latest version by default.

You can install a specific version by changing

```bash
pip install <package_name>
```

to

```bash
pip install <package_name>==<version_number>
```

## Import & Reference

```python

# Note: The example function used in all cases is the 'color' function

# Import
import Luci_Code_tools
Luci_Code_tools.color("HelloWorld", 32, None, 1, 2)

# Import + as
import Luci_Code_tools as lct
lct.color("HelloWorld", 32, None, 1, 2)

# Reference
from Luci_Code_tools import color
color("HelloWorld", 32, None, 1, 2)

# Reference + as
from Luci_Code_tools import color as cl
cl("HelloWorld", 32, None, 1, 2)

```

---

# Parameter Introduction

The output style for `line` is:

```json
{
    "line": 0,
    "data": "Hello",
    "data": "World",
    "output": 2
}
```
`"output": 2` corresponds to two output functions.

Output effect:

HelloWorld ("Hello" and "World" are two separate strings)

```json
{
    "line": 1,
    "data": "Hello",
    "data": "World",
    "output": 2
}
```
`"output": 2` corresponds to two output functions.

Output effect:

Hello

(There is actually no blank line here)

World

```json
{
    "line": 2,
    "data": "Hello",
    "data": "World",
    "output": 2
}
```
`"output": 2` corresponds to two output functions.

Output effect:

Hello

(There is actually a blank line in between)

World

The `line` parameter can be set higher, but I need to limit the number of tests due to space constraints 🐱

Adjust the number of blank lines numerically to improve readability.

## Function Parameters

Let's first list the functions currently used in the code.

## Functions

- color_rgb

- color

- clear_screen

- safe_input

- safe_int

- safe_float

## All Parameters

---

First, let's introduce **color_rgb**

- color_rgb

This function manages RGB color output; it is constructed using **ANSI escape sequences + parameters**.

Parameters include:

data r g b mode line

- data

The `data` parameter controls the **content to be output**.

- r

- g

- b

These three parameters are specified in the order of R, G, and B; for example, `255, 0, 0` represents **pure red**.

- mode

The `mode` parameter controls the output mode; a table of specific output modes is provided at the end.

- line

The `line` parameter accepts an integer; specific details can be found in the **"Parameter Introduction"** section above.

---

- color

This function manages colored text using ANSI escape sequences 🤔

- data

Manages the string to be output with color formatting.

- text_color

Controls the output color using ANSI color codes; no need for complex adjustments. Detailed parameters are in the parameter table at the end.

- bg_color

Controls the background color of the output using ANSI color codes. Detailed parameters are in the parameter table at the end.

- mode

Controls the output/display style using ANSI escape sequences.

- line

Serves the same purpose as the `color_rgb` parameter mentioned earlier; both control the number of blank lines between outputs.

---

- clear_screen

`clear_screen` takes no arguments, but here is an introduction to the function.

**Function Introduction**

This function:

> Automatically detects the system and uses the corresponding screen-clearing command.

For example:

Android -> `clear` (Linux kernel)

Linux -> `clear`

Windows -> `cls`

It switches the command used based on the OS.

> Ensures absolute protection against injection attacks by using a controlled list of parameters and commands for clearing the screen.

> 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).

> Can output 250 blank lines to "clear the screen" even if the terminal height cannot be detected.

---

- safe_input

- safe_int

- safe_float

These `safe_*` functions share the same parameters:

prompt | Prompt text

text_color | Prompt text color

bg_color | Prompt background color

mode | Prompt output style

- prompt

The `prompt` parameter serves the same purpose as the `data` parameter.

- text_color

- bg_color

- mode

These three parameters are identical to the corresponding ones in `color` and `color_rgb`, serving the same function.

---

# Parameter Table

## Foreground Color

| Foreground Color - Value | Effect |
| --- | --- |
| 30 | Black |
| 31 | Red |
| 32 | Green |
| 33 | Yellow |
| 34 | Blue |
| 35 | Purple |
| 36 | Cyan |
| 37 | White |

## Foreground Color - Light/Bright

| Foreground Color - Value | Effect |
| --- | --- |
| 90 | Dark gray |
| 91 | Light red |
| 92 | Light green |
| 93 | Light yellow |
| 94 | Light blue |
| 95 | Light purple |
| 96 | Light cyan |
| 97 | Light gray |

## Background Color

| Background Color - Value | Effect |
| --- | --- |
| 40 | Black |
| 41 | Red |
| 42 | Green |
| 43 | Yellow |
| 44 | Blue |
| 45 | Purple |
| 46 | Cyan |
| 47 | White |

## Background Color - Light Shades

| Background Color - Value | Effect |
| --- | --- |
| 100 | Dark gray |
| 101 | Light red |
| 102 | Light green |
| 103 | Light yellow |
| 104 | Light blue |
| 105 | Light purple |
| 106 | Light cyan |
| 107 | Pure white |

## Output Mode

| Display Mode - Value | Effect |
| --- | --- |
| 0 | Default |
| 1 | Highlight + Bold |
| 2 | Dim |
| 3 | Italic (may not be supported by some terminals) |
| 4 | Underline |
| 5 | Blink |
| 6 | Rapid blink (may not be supported by some terminals) |
| 7 | Invert (swap foreground and background colors) |
| 8 | Hidden |
| 9 | Strikethrough |

---

# Credits & Acknowledgments (Ranked by contribution level, top to bottom)

| Person/Entity | Contribution |
| --- | --- |
| DeepSeek | Build, packaging, and upload tutorial |
| DeepSeek | Provided improvement suggestions |
| DeepSeek | Environment help |
| Luci\_Code | Writing |
| Luci\_Code | Packaging |
| Luci\_Code | Creation |
| Luci\_Code | Building |
| Luci\_Code | Uploading |
| Luci\_Code | Conceptualization |

---

# Quick Start

## Input and Output

```python
from Luci_Code_tools import color, safe_input

text = safe_input("Please enter text: ", 32, None, 1)
color(f"You entered {text}", 32, None, 1, 2)
```

## Calculator

```python
from Luci_Code_tools import color, safe_float, safe_input
from sys import exit

color("=== Calculator ===", 32, None, 1, 2)
while True:
    num1 = safe_float("Enter the first number: ", 32, None, 1)
    num2 = safe_float("Enter the second number: ", 32, None, 1)
    operators = safe_input("Enter operator (+, -, *, /, type 'quit' to exit): ")
    if operators == "+":
        color(f"Result: {num1 + num2}\n==========", 32, None, 1, 2)
        continue
    elif operators == "-":
        color(f"Result: {num1 - num2}\n==========", 32, None, 1, 2)
        continue
    elif operators == "*":
        color(f"Result: {num1 * num2}\n==========", 32, None, 1, 2)
        continue
    elif operators == "/":
        if num2 == 0:
            color("Divisor cannot be zero\n==========", 33, None, 1, 2)
            continue
        else:
            color(f"Result: {num1 / num2}\n==========", 32, None, 1, 2)
            continue
    elif operators == "quit":
        color("=== Exit successful ===", 32, None, 1, 2)
        exit(0)
    else:
        color("Invalid operator!\n==========", 33, None, 1, 2)
        continue
```

## File Read and Write

```python
from Luci_Code_tools import color
from os import remove
from json import load, dump, JSONDecodeError

JSON = {
    "test": "This is Test content",
    "test2": "This is Test content 2"
}

FILE_PATH = "user.json"

def fix_json(prompt: str) -> None:
    color(prompt, 33, None, 1, 2)
    with open(FILE_PATH, "w", encoding="utf-8") as f:
        dump(JSON, f, ensure_ascii=False, indent=4, sort_keys=True)
    color("Repair successful! Please restart the program", 32, None, 1)

try:
    with open(FILE_PATH, "r", encoding="utf-8") as f:
        data = load(f)
except FileNotFoundError:
    fix_json("File not found, repairing...")
except JSONDecodeError:
    fix_json("JSON file format or content error")
else:
    content_1 = data["test"]
    content_2 = data["test2"]
    color(f"Content 1: {content_1}\nContent 2: {content_2}\n\nTest successful!", 32, None, 1, 2)
    remove(FILE_PATH)
```
