Skip to content

Commit

Permalink
feat(pypi package update): add new code and debug to push the pypi pa…
Browse files Browse the repository at this point in the history
…ckage

提交彩色打印到远程pypi仓库
  • Loading branch information
bruce1408 committed Feb 26, 2024
1 parent dbceab0 commit 513daa5
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Basic_Operation/0-1.Basic/1_1_Basic_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ def forward(self, x):
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable

print("="*50)
word_to_ix = {'hello': 1, 'world': 2}
embeds = nn.Embedding(7, 5, padding_idx=0)
hello_idx = torch.LongTensor([word_to_ix['hello']])
hello_embed = embeds(hello_idx)
print(hello_embed)
print(hello_embed.shape)
print(embeds(torch.LongTensor([1, 4, 3])))
print(embeds(torch.LongTensor([[1, 4, 3], [2, 3, 1]])).shape)
print("the two shape is :\n",embeds(torch.LongTensor([[1, 4, 3], [2, 3, 1]])).shape)

inputs = torch.randint(1, 7, (3, 3))
print(embeds(inputs).shape)
Expand Down
60 changes: 60 additions & 0 deletions Colorful_Print/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
以下是使用Markdown格式编写的上述Python代码功能和使用文档:

---

## 使用文档

这段Python代码提供了两个函数,用于在终端中打印彩色的文本框,以增强文本信息的视觉表现。以下是每个函数的详细说明和使用示例。

### 1. `print_colored_box_line` 函数

#### 功能描述

`print_colored_box_line` 函数用于在终端打印一个含有标题和消息的彩色文本框。这个文本框具有上下边框、居中的标题和消息,用户可以自定义文本和框的颜色及属性(例如加粗)。此函数适用于需要强调显示重要信息或区分文本段落的场景。

#### 参数说明

- `title`: 文本框中心的标题文本。
- `message`: 文本框中的消息文本。
- `attrs`: 文本属性列表(例如 `['bold']` 表示加粗文本)。
- `text_color`: 文本的颜色。
- `box_color`: 文本框的颜色。
- `box_width`: 文本框的宽度,默认值为80字符。

#### 使用示例

```python
from printk import print_colored_box, print_colored_box_line

print_colored_box_line("警告", "请立即检查系统!", attrs=['bold'], text_color='red', box_color='yellow')
```

此示例将在终端打印一个黄色背景框,其中包含红色加粗的“警告”标题和“请立即检查系统!”的消息。

### 2. `print_colored_box` 函数

#### 功能描述

`print_colored_box` 函数用于在终端打印一个彩色边框的文本框,可以选择为文本添加背景颜色。此函数适合用于突出显示单条信息,通过颜色和边框的变化来吸引用户的注意。

#### 参数说明

- `text`: 文本框中显示的文本。
- `text_background`: 布尔值,指定是否为文本添加背景颜色。
- `text_color`: 文本的颜色。
- `box_color`: 边框的颜色。
- `background_color`: 文本的背景颜色,仅在 `text_background` 为 True 时适用。

#### 使用示例

```python
print_colored_box("操作成功", text_background=True, text_color='green', box_color='green', background_color='on_white')
```

此示例将在终端打印一个绿色边框和文本的文本框,如果支持的话,文本背景为白色。

---

### 概述

通过使用这两个函数,开发者可以在他们的Python应用程序中以视觉上引人注目的方式显示信息,如日志消息、警告或成功提示。自定义文本、背景和边框颜色以及文本属性使得集成这些彩色文本框变得简单,从而提升用户的交互体验。
3 changes: 1 addition & 2 deletions Colorful_Print/printk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import print_colored_box_line
from . import print_colored_box
from .printk import print_colored_box, print_colored_box_line
48 changes: 48 additions & 0 deletions Colorful_Print/printk/printk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@


def print_colored_box_line(title, message, attrs=['bold'], text_color='white', box_color='yellow',box_width=80):
# 定义方框的宽度为终端的宽度,这里假定为80字符宽
# 详细描述代码的参数和功能
"""
print("使用说明:")
print("print_colored_box_line(title, message, attrs=['bold'], text_color='white', box_color='yellow',box_width=80)")
print("title: 方框的标题")
print("message: 方框的消息")
print("attrs: 方框的属性,默认为['bold']")
print("text_color: 文本颜色,默认为'white'")
print("box_color: 方框颜色,默认为'yellow'")
print("box_width: 方框宽度,默认为80")
print("\n")
print("示例:")
print("print_colored_box_line('Title', 'Hello, World!', attrs=['bold'], text_color='white', box_color='yellow',box_width=80)")
print("print_colored_box_line('Title', 'Hello, World!', attrs=['bold'], text_color='white', box_color='green',box_width=80)")
print("print_colored_box_line('Title', 'Hello, World!', attrs=['bold'], text_color='white', box_color='red',box_width=80)")
print("print_colored_box_line('Title', 'Hello, World!', attrs=['bold'], text_color='white', box_color='blue',box_width=80)")
print("print_colored_box_line('Title', 'Hello, World!', attrs=['bold'], text_color='white', box_color='magenta',box_width=80)")
print("print_colored_box_line('Title', 'Hello, World!', attrs=['bold'], text_color='white', box_color='cyan',box_width=80)")
print("print_colored_box_line('Title', 'Hello, World!', attrs=['bold'], text_color='white', box_color='grey',box_width=80)")
print("print_colored_box_line('Title', 'Hello, World!', attrs=['bold'], text_color='white', box_color='black',box_width=80)")
print("print_colored_box_line('Title', 'Hello, World!', attrs=['bold'], text_color='white', box_color='white',box_width=80)")
print("\n")
打印彩色方框
"""
# 定义方框的宽度为终端的宽度,这里假定为80字符宽
box_width = 80

Expand All @@ -27,6 +52,29 @@ def print_colored_box_line(title, message, attrs=['bold'], text_color='white', b


def print_colored_box(text, text_background=False, text_color='white', box_color='green', background_color='on_white'):
# 添加代码使用说明,以及一些示例
"""
print("使用说明:")
print("print_colored_box(text, text_background=False, text_color='white', box_color='green', background_color='on_white')")
print("text: 要打印的文本")
print("text_background: 是否为文本添加背景色,默认为False")
print("text_color: 文本颜色,默认为'white'")
print("box_color: 方框颜色,默认为'green'")
print("background_color: 文本背景色,默认为'on_white'")
print("\n")
print("示例:")
print("print_colored_box('Hello, World!', text_background=True, text_color='white', box_color='green', background_color='on_white')")
print("print_colored_box('Hello, World!', text_background=True, text_color='white', box_color='green', background_color='on_red')")
print("print_colored_box('Hello, World!', text_background=True, text_color='white', box_color='green', background_color='on_yellow')")
print("print_colored_box('Hello, World!', text_background=True, text_color='white', box_color='green', background_color='on_blue')")
print("print_colored_box('Hello, World!', text_background=True, text_color='white', box_color='green', background_color='on_magenta')")
print("print_colored_box('Hello, World!', text_background=True, text_color='white', box_color='green', background_color='on_cyan')")
print("print_colored_box('Hello, World!', text_background=True, text_color='white', box_color='green', background_color='on_grey')")
print("print_colored_box('Hello, World!', text_background=True, text_color='white', box_color='green', background_color='on_black')")
print("print_colored_box('Hello, World!', text_background=True, text_color='white', box_color='green', background_color='on_white')")
print("\n")
打印彩色方框
"""
# 测量文本长度,并为方框的左右添加空格
padded_text = " " + text + " "
text_length = len(padded_text)
Expand Down
17 changes: 14 additions & 3 deletions Colorful_Print/setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
from setuptools import setup, find_packages

# read the contents of your README file
from os import path
this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()


setup(
name="printk",
version="0.1",
# readme file
long_description=long_description,
long_description_content_type='text/markdown',
# package information

name="printcolorful",
version="0.1.7",
packages=find_packages(),
description="A colorful print tool for python",
author="bruce_cui",
author_email="[email protected]",
install_requires=[
# 依赖列表
# 例如: "requests >= 2.22.0"
"termcolor >= 2.3.0",
],
)

0 comments on commit 513daa5

Please sign in to comment.