newrcc 0.5.1__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.
- newrcc-0.5.1/PKG-INFO +140 -0
- newrcc-0.5.1/README.md +123 -0
- newrcc-0.5.1/newrcc/__init__.py +3 -0
- newrcc-0.5.1/newrcc/c_color.py +96 -0
- newrcc-0.5.1/newrcc/c_console.py +359 -0
- newrcc-0.5.1/newrcc/c_error.py +26 -0
- newrcc-0.5.1/newrcc.egg-info/PKG-INFO +140 -0
- newrcc-0.5.1/newrcc.egg-info/SOURCES.txt +10 -0
- newrcc-0.5.1/newrcc.egg-info/dependency_links.txt +1 -0
- newrcc-0.5.1/newrcc.egg-info/top_level.txt +1 -0
- newrcc-0.5.1/setup.cfg +4 -0
- newrcc-0.5.1/setup.py +23 -0
newrcc-0.5.1/PKG-INFO
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: newrcc
|
|
3
|
+
Version: 0.5.1
|
|
4
|
+
Summary: A tool that can make your console output beautiful.
|
|
5
|
+
Author: RestRegular
|
|
6
|
+
Author-email: 3228097751@qq.com
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: author-email
|
|
13
|
+
Dynamic: classifier
|
|
14
|
+
Dynamic: description
|
|
15
|
+
Dynamic: description-content-type
|
|
16
|
+
Dynamic: summary
|
|
17
|
+
|
|
18
|
+
# NewRcc
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
## Logo
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+

|
|
25
|
+
## Welcome
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
Welcome to view this instruction document. This is a
|
|
29
|
+
toolkit that can make the output of your console more
|
|
30
|
+
beautiful. It not only supports controlling the
|
|
31
|
+
**text style** of the output in your console, but also
|
|
32
|
+
supports conveniently helping you quickly build console
|
|
33
|
+
**progress bars** with multiple styles. Come and install
|
|
34
|
+
it and try to beautify the console of your project.
|
|
35
|
+
|
|
36
|
+
**Installation Guide**
|
|
37
|
+
|
|
38
|
+
First, make sure that the pip package management tool
|
|
39
|
+
of Python has been installed on your
|
|
40
|
+
computer.
|
|
41
|
+
|
|
42
|
+
Then enter the following command in the console.
|
|
43
|
+
```
|
|
44
|
+
pip install newrcc
|
|
45
|
+
```
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
# Import several important members in the NewRcc package.
|
|
52
|
+
from newrcc.c_color import TextColor
|
|
53
|
+
import newrcc.c_console
|
|
54
|
+
|
|
55
|
+
"""
|
|
56
|
+
Use the colorfulText function in CConsole to convert
|
|
57
|
+
ordinary text into colorful text.
|
|
58
|
+
"""
|
|
59
|
+
print(CConsole.ctext("Hello NewRcc!", TextColor.GREEN))
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
Directly use the printColorfulText function in CConsole
|
|
63
|
+
to print colorful text in the console.
|
|
64
|
+
"""
|
|
65
|
+
CConsole.printColorfulText("Hello NewRcc!", TextColor.BLUE)
|
|
66
|
+
|
|
67
|
+
"""
|
|
68
|
+
Use the ProcessBar class in CConsole to construct a progress
|
|
69
|
+
bar object.
|
|
70
|
+
"""
|
|
71
|
+
process_bar = CConsole.ProcessBar("Start", "End", ...)
|
|
72
|
+
|
|
73
|
+
"""
|
|
74
|
+
Use the draw function of the ProcessBar class to draw the image
|
|
75
|
+
of a certain progress point, and use the erase function to clear
|
|
76
|
+
the last drawing.
|
|
77
|
+
Reasonably use these two functions in an operation process to
|
|
78
|
+
achieve real-time progress display effect.
|
|
79
|
+
"""
|
|
80
|
+
process_bar.draw()
|
|
81
|
+
process_bar.erase()
|
|
82
|
+
```
|
|
83
|
+
## Detailed Documentation
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
For more detailed explanation documents, please visit the link: [Detail Doc ](https://#) .
|
|
87
|
+
## Function Features
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
- It can run normally on systems that support
|
|
91
|
+
[ANSI escape sequences](https://baike.baidu.com/item/ANSI转义序列/22735729?fr=ge_ala).
|
|
92
|
+
- When it encounters an exception during operation,
|
|
93
|
+
it will uniformly throw the `_CError` exception class
|
|
94
|
+
in CError, which is inherited from `Exception`.
|
|
95
|
+
- It supports most common colors, including red, yellow,
|
|
96
|
+
blue, green, cyan, purple, and gray. At the same time,
|
|
97
|
+
it also supports [RGB color](https://baike.baidu.com/item/RGB/342517?fr=ge_ala) codes to create objects
|
|
98
|
+
of the `Color` class in CColor. For specific operations,
|
|
99
|
+
please refer to the [Detailed Documentation](#detailed-documentation).
|
|
100
|
+
- It supports other text styles besides text color, such
|
|
101
|
+
as **bold**, *italic*, <u>underline</u>, ~~middleline~~, etc.
|
|
102
|
+
- For other features, please refer to the
|
|
103
|
+
[Detail Documentation](#detailed-documentation).
|
|
104
|
+
## Developer Contact Information
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
**RestRegular**
|
|
108
|
+
|
|
109
|
+
**email**: [3228097751@qq.com](https://www.qq.com)
|
|
110
|
+
|
|
111
|
+
**GitHub**: [RestRegular](https://github.com/RestRegular)
|
|
112
|
+
## Known Issues and Limitations
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
At present, the function of quickly building a table in
|
|
116
|
+
the console has been initially completed, but it is still
|
|
117
|
+
immature. **The known problem is that cells cannot span rows.**
|
|
118
|
+
<p style="color: red; font-style: italic;">
|
|
119
|
+
Warning: Do not use the row-spanning function in the table.
|
|
120
|
+
</p>
|
|
121
|
+
|
|
122
|
+
## Version _NewRcc-0.1.4_
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
**Contents of This Version Update**
|
|
126
|
+
1. A _README.md_ file has been added.
|
|
127
|
+
2. A project logo has been added.
|
|
128
|
+
3. Some potential problems have been found and marked in the README.md file.
|
|
129
|
+
4. A display error of README.md file has been fixed.
|
|
130
|
+
|
|
131
|
+
## Author
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
**RestRegular**
|
|
135
|
+
|
|
136
|
+
## Special Thanks
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
Waiting for occupancy. ^_^
|
|
140
|
+
|
newrcc-0.5.1/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# NewRcc
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
## Logo
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+

|
|
8
|
+
## Welcome
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
Welcome to view this instruction document. This is a
|
|
12
|
+
toolkit that can make the output of your console more
|
|
13
|
+
beautiful. It not only supports controlling the
|
|
14
|
+
**text style** of the output in your console, but also
|
|
15
|
+
supports conveniently helping you quickly build console
|
|
16
|
+
**progress bars** with multiple styles. Come and install
|
|
17
|
+
it and try to beautify the console of your project.
|
|
18
|
+
|
|
19
|
+
**Installation Guide**
|
|
20
|
+
|
|
21
|
+
First, make sure that the pip package management tool
|
|
22
|
+
of Python has been installed on your
|
|
23
|
+
computer.
|
|
24
|
+
|
|
25
|
+
Then enter the following command in the console.
|
|
26
|
+
```
|
|
27
|
+
pip install newrcc
|
|
28
|
+
```
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
# Import several important members in the NewRcc package.
|
|
35
|
+
from newrcc.c_color import TextColor
|
|
36
|
+
import newrcc.c_console
|
|
37
|
+
|
|
38
|
+
"""
|
|
39
|
+
Use the colorfulText function in CConsole to convert
|
|
40
|
+
ordinary text into colorful text.
|
|
41
|
+
"""
|
|
42
|
+
print(CConsole.ctext("Hello NewRcc!", TextColor.GREEN))
|
|
43
|
+
|
|
44
|
+
"""
|
|
45
|
+
Directly use the printColorfulText function in CConsole
|
|
46
|
+
to print colorful text in the console.
|
|
47
|
+
"""
|
|
48
|
+
CConsole.printColorfulText("Hello NewRcc!", TextColor.BLUE)
|
|
49
|
+
|
|
50
|
+
"""
|
|
51
|
+
Use the ProcessBar class in CConsole to construct a progress
|
|
52
|
+
bar object.
|
|
53
|
+
"""
|
|
54
|
+
process_bar = CConsole.ProcessBar("Start", "End", ...)
|
|
55
|
+
|
|
56
|
+
"""
|
|
57
|
+
Use the draw function of the ProcessBar class to draw the image
|
|
58
|
+
of a certain progress point, and use the erase function to clear
|
|
59
|
+
the last drawing.
|
|
60
|
+
Reasonably use these two functions in an operation process to
|
|
61
|
+
achieve real-time progress display effect.
|
|
62
|
+
"""
|
|
63
|
+
process_bar.draw()
|
|
64
|
+
process_bar.erase()
|
|
65
|
+
```
|
|
66
|
+
## Detailed Documentation
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
For more detailed explanation documents, please visit the link: [Detail Doc ](https://#) .
|
|
70
|
+
## Function Features
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
- It can run normally on systems that support
|
|
74
|
+
[ANSI escape sequences](https://baike.baidu.com/item/ANSI转义序列/22735729?fr=ge_ala).
|
|
75
|
+
- When it encounters an exception during operation,
|
|
76
|
+
it will uniformly throw the `_CError` exception class
|
|
77
|
+
in CError, which is inherited from `Exception`.
|
|
78
|
+
- It supports most common colors, including red, yellow,
|
|
79
|
+
blue, green, cyan, purple, and gray. At the same time,
|
|
80
|
+
it also supports [RGB color](https://baike.baidu.com/item/RGB/342517?fr=ge_ala) codes to create objects
|
|
81
|
+
of the `Color` class in CColor. For specific operations,
|
|
82
|
+
please refer to the [Detailed Documentation](#detailed-documentation).
|
|
83
|
+
- It supports other text styles besides text color, such
|
|
84
|
+
as **bold**, *italic*, <u>underline</u>, ~~middleline~~, etc.
|
|
85
|
+
- For other features, please refer to the
|
|
86
|
+
[Detail Documentation](#detailed-documentation).
|
|
87
|
+
## Developer Contact Information
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
**RestRegular**
|
|
91
|
+
|
|
92
|
+
**email**: [3228097751@qq.com](https://www.qq.com)
|
|
93
|
+
|
|
94
|
+
**GitHub**: [RestRegular](https://github.com/RestRegular)
|
|
95
|
+
## Known Issues and Limitations
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
At present, the function of quickly building a table in
|
|
99
|
+
the console has been initially completed, but it is still
|
|
100
|
+
immature. **The known problem is that cells cannot span rows.**
|
|
101
|
+
<p style="color: red; font-style: italic;">
|
|
102
|
+
Warning: Do not use the row-spanning function in the table.
|
|
103
|
+
</p>
|
|
104
|
+
|
|
105
|
+
## Version _NewRcc-0.1.4_
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
**Contents of This Version Update**
|
|
109
|
+
1. A _README.md_ file has been added.
|
|
110
|
+
2. A project logo has been added.
|
|
111
|
+
3. Some potential problems have been found and marked in the README.md file.
|
|
112
|
+
4. A display error of README.md file has been fixed.
|
|
113
|
+
|
|
114
|
+
## Author
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
**RestRegular**
|
|
118
|
+
|
|
119
|
+
## Special Thanks
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
Waiting for occupancy. ^_^
|
|
123
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
from typing import Union, Tuple
|
|
2
|
+
|
|
3
|
+
from newrcc import c_error
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
'RESET',
|
|
7
|
+
'TextColor',
|
|
8
|
+
'BackgroundColor',
|
|
9
|
+
'Decoration'
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
RESET = '\033[0m'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Color:
|
|
16
|
+
def __init__(self, color: Union[str, Tuple[int, int, int]]):
|
|
17
|
+
if isinstance(color, str):
|
|
18
|
+
self.colorcode = color
|
|
19
|
+
elif isinstance(color, tuple):
|
|
20
|
+
Color.__RGBColor(self, color)
|
|
21
|
+
else:
|
|
22
|
+
raise CError.CDColorUndefinedError(color)
|
|
23
|
+
|
|
24
|
+
def __RGBColor(self, color: Tuple[int, int, int]):
|
|
25
|
+
for code in color:
|
|
26
|
+
if not (0 <= code <= 255):
|
|
27
|
+
raise CError.CDColorUndefinedError(color)
|
|
28
|
+
if isinstance(self, TextColor):
|
|
29
|
+
_type = '38'
|
|
30
|
+
elif isinstance(self, BackgroundColor):
|
|
31
|
+
_type = '48'
|
|
32
|
+
else:
|
|
33
|
+
raise CError.CDColorUndefinedError(color)
|
|
34
|
+
self.colorcode = f'\033[{_type};2;{color[0]};{color[1]};{color[2]}m'
|
|
35
|
+
|
|
36
|
+
def __str__(self):
|
|
37
|
+
return self.colorcode
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class TextColor(Color):
|
|
41
|
+
RED = '\033[31m'
|
|
42
|
+
GREEN = '\033[32m'
|
|
43
|
+
YELLOW = '\033[33m'
|
|
44
|
+
BLUE = '\033[34m'
|
|
45
|
+
PURPLE = '\033[35m'
|
|
46
|
+
CYAN = '\033[36m'
|
|
47
|
+
GRAY = '\033[90m'
|
|
48
|
+
WHITE = '\033[38m'
|
|
49
|
+
LIGHT_GRAY = '\033[37m'
|
|
50
|
+
LIGHT_RED = '\033[91m'
|
|
51
|
+
LIGHT_GREEN = '\033[92m'
|
|
52
|
+
LIGHT_YELLOW = '\033[93m'
|
|
53
|
+
LIGHT_BLUE = '\033[94m'
|
|
54
|
+
LIGHT_PURPLE = '\033[95m'
|
|
55
|
+
LIGHT_CYAN = '\033[96m'
|
|
56
|
+
LIGHT_WHITE = '\033[97m'
|
|
57
|
+
|
|
58
|
+
def __init__(self, color: Union[str, Tuple[int, int, int]]):
|
|
59
|
+
super().__init__(color)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class BackgroundColor(Color):
|
|
63
|
+
BLACK = '\033[40m'
|
|
64
|
+
RED = '\033[41m'
|
|
65
|
+
GREEN = '\033[42m'
|
|
66
|
+
YELLOW = '\033[43m'
|
|
67
|
+
BLUE = '\033[44m'
|
|
68
|
+
PURPLE = '\033[45m'
|
|
69
|
+
CYAN = '\033[46m'
|
|
70
|
+
GRAY = '\033[47m'
|
|
71
|
+
|
|
72
|
+
def __init__(self, color: Union[str, Tuple[int, int, int]]):
|
|
73
|
+
super().__init__(color)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class Decoration:
|
|
77
|
+
BOLD = '\033[1m'
|
|
78
|
+
ITALIC = '\033[3m'
|
|
79
|
+
L_UNDERLINE = '\033[4m'
|
|
80
|
+
REVERSE = '\033[7m'
|
|
81
|
+
LINE_THROUGH = '\033[9m'
|
|
82
|
+
B_UNDERLINE = '\033[21m'
|
|
83
|
+
|
|
84
|
+
def __init__(self, decoration: str):
|
|
85
|
+
self.decoration = decoration
|
|
86
|
+
|
|
87
|
+
def __str__(self):
|
|
88
|
+
return self.decoration
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def main():
|
|
92
|
+
print(f"{TextColor.WHITE}你好{TextColor.LIGHT_GRAY}hello{TextColor.GRAY}world{RESET}")
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == '__main__':
|
|
96
|
+
main()
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
from typing import Union, Tuple, List, Iterable, Any, Optional
|
|
3
|
+
|
|
4
|
+
from newrcc import c_color as cc
|
|
5
|
+
from newrcc import c_error as ce
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
'ctext',
|
|
9
|
+
'cprint',
|
|
10
|
+
'ProcessBar',
|
|
11
|
+
'TBlock',
|
|
12
|
+
'TRow',
|
|
13
|
+
'Table',
|
|
14
|
+
'process'
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def ctext(text: str,
|
|
19
|
+
color: Union[None, str, cc.Color, Tuple[
|
|
20
|
+
Union[cc.TextColor, Tuple[int, int, int]],
|
|
21
|
+
Union[cc.BackgroundColor, Tuple[int, int, int]]
|
|
22
|
+
]],
|
|
23
|
+
decorations: List[Union[cc.Decoration, str]] = None,
|
|
24
|
+
reset: bool = True) -> str:
|
|
25
|
+
if decorations is not None:
|
|
26
|
+
for decoration in decorations:
|
|
27
|
+
if isinstance(decoration, str):
|
|
28
|
+
text = decoration + text
|
|
29
|
+
else:
|
|
30
|
+
text = str(decoration) + text
|
|
31
|
+
if isinstance(color, cc.Color):
|
|
32
|
+
text = str(color) + text
|
|
33
|
+
elif isinstance(color, tuple):
|
|
34
|
+
if isinstance(color[0], tuple):
|
|
35
|
+
text = str(cc.TextColor(color[0])) + text
|
|
36
|
+
else:
|
|
37
|
+
text = str(color[0]) + text
|
|
38
|
+
if isinstance(color[1], tuple):
|
|
39
|
+
text = str(cc.BackgroundColor(color[1])) + text
|
|
40
|
+
else:
|
|
41
|
+
text = str(color[1]) + text
|
|
42
|
+
elif isinstance(color, str):
|
|
43
|
+
text = color + (cc.RESET + color).join(text.split(cc.RESET))
|
|
44
|
+
elif color is not None:
|
|
45
|
+
raise cc.CDError.CDUnexpectedColorInputError(color, 'colorfulText')
|
|
46
|
+
if reset and color is not None:
|
|
47
|
+
text += cc.RESET
|
|
48
|
+
return text
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def cprint(
|
|
52
|
+
text: str,
|
|
53
|
+
color: Union[str, cc.Color, Tuple[
|
|
54
|
+
Union[cc.TextColor, str, Tuple[int, int, int]],
|
|
55
|
+
Union[cc.BackgroundColor, str, Tuple[int, int, int]]
|
|
56
|
+
]],
|
|
57
|
+
decorations: List[Union[cc.Decoration, str]] = None,
|
|
58
|
+
reset: bool = True,
|
|
59
|
+
end: str = '\n'
|
|
60
|
+
) -> None:
|
|
61
|
+
print(ctext(text, color, decorations, reset), end=end)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class ProcessBar:
|
|
65
|
+
def __init__(self,
|
|
66
|
+
prefix: str,
|
|
67
|
+
suffix: str,
|
|
68
|
+
total: int,
|
|
69
|
+
length: int = 20,
|
|
70
|
+
title_color: Union[str, cc.Color] = None,
|
|
71
|
+
frame_color: Union[str, cc.Color] = None,
|
|
72
|
+
show_frame_border: bool = True,
|
|
73
|
+
process_color: Union[str, cc.Color] = None,
|
|
74
|
+
value_color: Union[str, cc.Color] = None,
|
|
75
|
+
style: int = 1):
|
|
76
|
+
self.prefix = prefix
|
|
77
|
+
self.suffix = suffix
|
|
78
|
+
self.length = length
|
|
79
|
+
self.total = total
|
|
80
|
+
self.process_color = process_color
|
|
81
|
+
self.frame_color = frame_color
|
|
82
|
+
self.show_frame_border = show_frame_border
|
|
83
|
+
self.title_color = title_color
|
|
84
|
+
self.value_color = value_color
|
|
85
|
+
self.extra_length = (8 * (process_color is not None) + 8 * (frame_color is not None) +
|
|
86
|
+
8 * (title_color is not None) + 12 * (value_color is not None))
|
|
87
|
+
self.process_length = self.extra_length
|
|
88
|
+
self.style = style
|
|
89
|
+
|
|
90
|
+
def draw(self, current: int) -> None:
|
|
91
|
+
real_length = int(self.length * current // self.total)
|
|
92
|
+
fix_length = max(len(self.prefix), len(self.suffix))
|
|
93
|
+
|
|
94
|
+
def getProcess():
|
|
95
|
+
_process = ''
|
|
96
|
+
if self.style == 1:
|
|
97
|
+
_process = (ctext('│' * self.show_frame_border, self.frame_color, reset=False) +
|
|
98
|
+
ctext('█' * real_length + ' ' * (self.length - real_length), self.process_color) +
|
|
99
|
+
ctext('│' * self.show_frame_border, self.frame_color))
|
|
100
|
+
elif self.style == 2:
|
|
101
|
+
_process = (ctext('│' * self.show_frame_border, self.frame_color, reset=False) +
|
|
102
|
+
ctext('█' * real_length, self.process_color) +
|
|
103
|
+
ctext('█' * (self.length - real_length), self.frame_color) +
|
|
104
|
+
ctext('│' * self.show_frame_border, self.frame_color))
|
|
105
|
+
elif self.style == 3:
|
|
106
|
+
_process = (ctext('│' * self.show_frame_border, self.frame_color, reset=False) +
|
|
107
|
+
ctext('━' * (real_length - 1), self.process_color, reset=False) +
|
|
108
|
+
'╸' * (self.length - real_length > 0) +
|
|
109
|
+
'━' * (self.length - real_length == 0) + cc.RESET +
|
|
110
|
+
ctext('━' * (self.length - real_length), self.frame_color, reset=False) +
|
|
111
|
+
ctext('│' * self.show_frame_border, self.frame_color))
|
|
112
|
+
return _process
|
|
113
|
+
|
|
114
|
+
if real_length < self.length:
|
|
115
|
+
process_ = (ctext(self.prefix + ' ' * (fix_length - len(self.prefix)), self.title_color) +
|
|
116
|
+
': ' +
|
|
117
|
+
getProcess() +
|
|
118
|
+
' ' +
|
|
119
|
+
ctext(str(round(current / self.total * 100, 3)) + '% ', self.value_color))
|
|
120
|
+
print(process_, end='')
|
|
121
|
+
self.process_length = len(process_)
|
|
122
|
+
else:
|
|
123
|
+
process_ = (ctext(self.suffix + ' ' * (fix_length - len(self.suffix)), self.title_color) +
|
|
124
|
+
': ' +
|
|
125
|
+
getProcess() +
|
|
126
|
+
' ' +
|
|
127
|
+
ctext(str(round(current / self.total * 100, 3)) + '% ', self.value_color))
|
|
128
|
+
print(process_)
|
|
129
|
+
|
|
130
|
+
def erase(self) -> None:
|
|
131
|
+
print('\b' * (self.process_length + self.extra_length), end='', flush=True)
|
|
132
|
+
|
|
133
|
+
def progress(self, iterator: Optional[Iterable[Any]] = None):
|
|
134
|
+
self.total = self.total if iterator is None else len(iterator)
|
|
135
|
+
for i in range(0, self.total):
|
|
136
|
+
self.draw(i + 1)
|
|
137
|
+
yield iterator[i] if iterator else i
|
|
138
|
+
self.erase()
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class TBlock:
|
|
142
|
+
def __init__(self,
|
|
143
|
+
item,
|
|
144
|
+
across_rows: int = 1,
|
|
145
|
+
across_columns: int = 1,
|
|
146
|
+
isnone: bool = False):
|
|
147
|
+
self.item = str(item)
|
|
148
|
+
self.across_rows = across_rows
|
|
149
|
+
self.across_columns = across_columns
|
|
150
|
+
self.row_across = (across_rows != 1)
|
|
151
|
+
self.column_across = (across_columns != 1)
|
|
152
|
+
self.isnone = isnone
|
|
153
|
+
|
|
154
|
+
def __str__(self):
|
|
155
|
+
if self.isnone:
|
|
156
|
+
return "<none>"
|
|
157
|
+
else:
|
|
158
|
+
return self.item
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
class TRow:
|
|
162
|
+
def __init__(self, blocks: List[TBlock]):
|
|
163
|
+
self.blocks = []
|
|
164
|
+
for block in blocks:
|
|
165
|
+
if block.column_across:
|
|
166
|
+
self.blocks.append(block)
|
|
167
|
+
i = 1
|
|
168
|
+
for _ in range(0, block.across_columns - 1):
|
|
169
|
+
self.blocks.append(TBlock('', across_columns=block.across_columns - i, isnone=True))
|
|
170
|
+
i += 1
|
|
171
|
+
else:
|
|
172
|
+
self.blocks.append(block)
|
|
173
|
+
length = 0
|
|
174
|
+
across_rows = 0
|
|
175
|
+
for block in blocks:
|
|
176
|
+
length += block.across_columns
|
|
177
|
+
across_rows = max(across_rows, block.across_rows)
|
|
178
|
+
block_length = []
|
|
179
|
+
for block in blocks:
|
|
180
|
+
block_length.append(len(str(block)))
|
|
181
|
+
if block.across_columns > 1:
|
|
182
|
+
for i in range(0, block.across_columns - 1):
|
|
183
|
+
block_length.append(0)
|
|
184
|
+
self.columns = length
|
|
185
|
+
self.across_rows = across_rows
|
|
186
|
+
self.block_length = block_length
|
|
187
|
+
|
|
188
|
+
def __blocks_str__(self):
|
|
189
|
+
string = '[ '
|
|
190
|
+
for block in self.blocks:
|
|
191
|
+
string += str(block) + ' '
|
|
192
|
+
string += ']'
|
|
193
|
+
return string
|
|
194
|
+
|
|
195
|
+
def __str__(self):
|
|
196
|
+
return f'row{"{"}across rows: {self.across_rows}, columns: {self.columns}, block length: {self.block_length}, blocks: {self.__blocks_str__()}{"}"}'
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class Table:
|
|
200
|
+
def getBlockMaxLength(self) -> List[int]:
|
|
201
|
+
block_max_length = [0 for _ in self.rows[0].block_length]
|
|
202
|
+
for _row in self.rows:
|
|
203
|
+
if len(block_max_length) != len(_row.block_length):
|
|
204
|
+
raise ce.CDTableBlockCountMismatchedError(_row, block_max_length)
|
|
205
|
+
i = 0
|
|
206
|
+
for length in _row.block_length:
|
|
207
|
+
block_max_length[i] = max(length, block_max_length[i])
|
|
208
|
+
i += 1
|
|
209
|
+
return block_max_length
|
|
210
|
+
|
|
211
|
+
def __init__(self, rows: List[TRow] = None):
|
|
212
|
+
self.rows = rows
|
|
213
|
+
row_length = 0
|
|
214
|
+
column_length = 0
|
|
215
|
+
for row in rows:
|
|
216
|
+
row_length += row.across_rows
|
|
217
|
+
column_length = max(column_length, row.columns)
|
|
218
|
+
self.row_length = row_length
|
|
219
|
+
self.column_length = column_length
|
|
220
|
+
self.block_max_length = self.getBlockMaxLength()
|
|
221
|
+
|
|
222
|
+
def append(self, row: TRow) -> None:
|
|
223
|
+
self.rows.append(row)
|
|
224
|
+
|
|
225
|
+
def getTableInfo(self) -> str:
|
|
226
|
+
return (f'table{"{"}row_length: {self.row_length}, column_length: {self.column_length},'
|
|
227
|
+
f' block max length: {self.block_max_length}{"}"}')
|
|
228
|
+
|
|
229
|
+
def __str__(self) -> str:
|
|
230
|
+
r_index = 0
|
|
231
|
+
while r_index < self.row_length:
|
|
232
|
+
if r_index == 0:
|
|
233
|
+
print(end='┌')
|
|
234
|
+
length_index = 0
|
|
235
|
+
while length_index < len(self.block_max_length):
|
|
236
|
+
print(end='─' * self.block_max_length[length_index])
|
|
237
|
+
if length_index == len(self.block_max_length) - 1:
|
|
238
|
+
print(end='┐\n')
|
|
239
|
+
else:
|
|
240
|
+
if self.rows[r_index].blocks[length_index].column_across:
|
|
241
|
+
print(end='─')
|
|
242
|
+
else:
|
|
243
|
+
print(end='┬')
|
|
244
|
+
length_index += 1
|
|
245
|
+
block_index = 0
|
|
246
|
+
for block in self.rows[r_index].blocks:
|
|
247
|
+
if not block.isnone:
|
|
248
|
+
print(end='│' + str(block) + ' ' * (self.block_max_length[block_index] - len(str(block))))
|
|
249
|
+
else:
|
|
250
|
+
print(end=' ' * (self.block_max_length[block_index] + 1))
|
|
251
|
+
block_index += 1
|
|
252
|
+
print(end='│\n')
|
|
253
|
+
else:
|
|
254
|
+
print(end='├')
|
|
255
|
+
length_index = 0
|
|
256
|
+
while length_index < len(self.block_max_length):
|
|
257
|
+
print(end='─' * self.block_max_length[length_index])
|
|
258
|
+
if length_index == len(self.block_max_length) - 1:
|
|
259
|
+
print(end='┤\n')
|
|
260
|
+
else:
|
|
261
|
+
if not self.rows[r_index].blocks[length_index].column_across and not \
|
|
262
|
+
self.rows[r_index - 1].blocks[length_index].column_across:
|
|
263
|
+
print(end='┼')
|
|
264
|
+
elif not self.rows[r_index].blocks[length_index].column_across and \
|
|
265
|
+
self.rows[r_index - 1].blocks[length_index].column_across:
|
|
266
|
+
print(end='┬')
|
|
267
|
+
elif self.rows[r_index].blocks[length_index].column_across and self.rows[r_index - 1].blocks[
|
|
268
|
+
length_index].column_across:
|
|
269
|
+
print(end='─')
|
|
270
|
+
elif self.rows[r_index].blocks[length_index].column_across and not \
|
|
271
|
+
self.rows[r_index - 1].blocks[length_index].column_across:
|
|
272
|
+
print(end='┴')
|
|
273
|
+
length_index += 1
|
|
274
|
+
block_index = 0
|
|
275
|
+
for block in self.rows[r_index].blocks:
|
|
276
|
+
if not block.isnone:
|
|
277
|
+
print(end='│' + str(block) + ' ' * (self.block_max_length[block_index] - len(str(block))))
|
|
278
|
+
else:
|
|
279
|
+
print(end=' ' * (self.block_max_length[block_index] + 1))
|
|
280
|
+
block_index += 1
|
|
281
|
+
print(end='│\n')
|
|
282
|
+
r_index += 1
|
|
283
|
+
length_index = 0
|
|
284
|
+
print(end='└')
|
|
285
|
+
while length_index < len(self.block_max_length):
|
|
286
|
+
print(end='─' * self.block_max_length[length_index])
|
|
287
|
+
if length_index == len(self.block_max_length) - 1:
|
|
288
|
+
print(end='┘\n')
|
|
289
|
+
else:
|
|
290
|
+
if self.rows[r_index - 1].blocks[length_index].column_across:
|
|
291
|
+
print(end='─')
|
|
292
|
+
else:
|
|
293
|
+
print(end='┴')
|
|
294
|
+
length_index += 1
|
|
295
|
+
return ''
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
"""
|
|
299
|
+
─ │ ┌ ┐ └ ┘ ┼ ├ ┤ ┬ ┴ █ ▓ ▒ ░ ↑ ↓ ← → ● ◦ ․·‥°º▫◌◯◻⁺ⁱ⁼∙⋱﹒·−-⁎‣−■■■■■■■■■■■■■ ━ ━ ╺ ╸
|
|
300
|
+
"""
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
@contextlib.contextmanager
|
|
304
|
+
def process(
|
|
305
|
+
prefix: str,
|
|
306
|
+
suffix: str,
|
|
307
|
+
total: int = 100,
|
|
308
|
+
length: int = 20,
|
|
309
|
+
title_color: Union[str, cc.Color] = cc.TextColor.BLUE,
|
|
310
|
+
frame_color: Union[str, cc.Color] = cc.TextColor.WHITE,
|
|
311
|
+
show_frame_border: bool = True,
|
|
312
|
+
process_color: Union[str, cc.Color] = cc.TextColor.GREEN,
|
|
313
|
+
value_color: Union[str, cc.Color] = cc.TextColor.WHITE,
|
|
314
|
+
style: int = 1):
|
|
315
|
+
bar = ProcessBar(
|
|
316
|
+
prefix=prefix,
|
|
317
|
+
suffix=suffix,
|
|
318
|
+
total=total,
|
|
319
|
+
length=length,
|
|
320
|
+
title_color=title_color,
|
|
321
|
+
frame_color=frame_color,
|
|
322
|
+
show_frame_border=show_frame_border,
|
|
323
|
+
process_color=process_color,
|
|
324
|
+
value_color=value_color,
|
|
325
|
+
style=style
|
|
326
|
+
)
|
|
327
|
+
try:
|
|
328
|
+
yield bar.progress
|
|
329
|
+
finally:
|
|
330
|
+
bar.erase()
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
def demo_colorful_text():
|
|
334
|
+
print("===== 彩色文本示例 =====")
|
|
335
|
+
# 基础颜色输出
|
|
336
|
+
cprint("普通红色文本", cc.TextColor.RED)
|
|
337
|
+
cprint("绿色背景文本", (None, cc.BackgroundColor.GREEN))
|
|
338
|
+
cprint("蓝底黄字", (cc.TextColor.YELLOW, cc.BackgroundColor.BLUE))
|
|
339
|
+
|
|
340
|
+
# 自定义RGB颜色
|
|
341
|
+
cprint("自定义粉色文本", cc.TextColor((255, 192, 203)))
|
|
342
|
+
cprint("青蓝色背景", (None, cc.BackgroundColor((0, 255, 255))))
|
|
343
|
+
|
|
344
|
+
# 带装饰的文本
|
|
345
|
+
cprint("加粗+下划线文本", cc.TextColor.CYAN,
|
|
346
|
+
decorations=[cc.Decoration.BOLD, cc.Decoration.L_UNDERLINE])
|
|
347
|
+
print(ctext(f"Hello {ctext('inner text', cc.TextColor.LIGHT_RED)} world!", cc.TextColor.LIGHT_BLUE))
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
def demo_progress_bar():
|
|
351
|
+
from time import sleep
|
|
352
|
+
print("===== 进度条示例 =====")
|
|
353
|
+
with process("下载 'newrcc' 中", "'newrcc' 下载完成", show_frame_border=False, style=3) as bar:
|
|
354
|
+
for _ in bar.progress():
|
|
355
|
+
sleep(0.01)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
if __name__ == "__main__":
|
|
359
|
+
demo_colorful_text()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
__all__ = [
|
|
2
|
+
'CDColorUndefinedError',
|
|
3
|
+
'CDUnexpectedColorInputError',
|
|
4
|
+
'CDTableBlockCountMismatchedError'
|
|
5
|
+
]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class _CDError(Exception):
|
|
9
|
+
def __init__(self, msg: str):
|
|
10
|
+
super().__init__(f'[CDError]: {msg}')
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CDColorUndefinedError(_CDError):
|
|
14
|
+
def __init__(self, undefined_color):
|
|
15
|
+
super().__init__(f'This color is undefined in CD standard color set. -> [{str(undefined_color)}]')
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class CDUnexpectedColorInputError(_CDError):
|
|
19
|
+
def __init__(self, unexpected_color, input_func: str):
|
|
20
|
+
super().__init__(
|
|
21
|
+
f'This color is an unexpected input for this function. [{str(unexpected_color)}] -> [{input_func}]')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class CDTableBlockCountMismatchedError(_CDError):
|
|
25
|
+
def __init__(self, wrong_row, right_length):
|
|
26
|
+
super().__init__(f'This table row\'s block count mismatched with other rows. {wrong_row} -> {right_length}')
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: newrcc
|
|
3
|
+
Version: 0.5.1
|
|
4
|
+
Summary: A tool that can make your console output beautiful.
|
|
5
|
+
Author: RestRegular
|
|
6
|
+
Author-email: 3228097751@qq.com
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: author-email
|
|
13
|
+
Dynamic: classifier
|
|
14
|
+
Dynamic: description
|
|
15
|
+
Dynamic: description-content-type
|
|
16
|
+
Dynamic: summary
|
|
17
|
+
|
|
18
|
+
# NewRcc
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
## Logo
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+

|
|
25
|
+
## Welcome
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
Welcome to view this instruction document. This is a
|
|
29
|
+
toolkit that can make the output of your console more
|
|
30
|
+
beautiful. It not only supports controlling the
|
|
31
|
+
**text style** of the output in your console, but also
|
|
32
|
+
supports conveniently helping you quickly build console
|
|
33
|
+
**progress bars** with multiple styles. Come and install
|
|
34
|
+
it and try to beautify the console of your project.
|
|
35
|
+
|
|
36
|
+
**Installation Guide**
|
|
37
|
+
|
|
38
|
+
First, make sure that the pip package management tool
|
|
39
|
+
of Python has been installed on your
|
|
40
|
+
computer.
|
|
41
|
+
|
|
42
|
+
Then enter the following command in the console.
|
|
43
|
+
```
|
|
44
|
+
pip install newrcc
|
|
45
|
+
```
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
# Import several important members in the NewRcc package.
|
|
52
|
+
from newrcc.c_color import TextColor
|
|
53
|
+
import newrcc.c_console
|
|
54
|
+
|
|
55
|
+
"""
|
|
56
|
+
Use the colorfulText function in CConsole to convert
|
|
57
|
+
ordinary text into colorful text.
|
|
58
|
+
"""
|
|
59
|
+
print(CConsole.ctext("Hello NewRcc!", TextColor.GREEN))
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
Directly use the printColorfulText function in CConsole
|
|
63
|
+
to print colorful text in the console.
|
|
64
|
+
"""
|
|
65
|
+
CConsole.printColorfulText("Hello NewRcc!", TextColor.BLUE)
|
|
66
|
+
|
|
67
|
+
"""
|
|
68
|
+
Use the ProcessBar class in CConsole to construct a progress
|
|
69
|
+
bar object.
|
|
70
|
+
"""
|
|
71
|
+
process_bar = CConsole.ProcessBar("Start", "End", ...)
|
|
72
|
+
|
|
73
|
+
"""
|
|
74
|
+
Use the draw function of the ProcessBar class to draw the image
|
|
75
|
+
of a certain progress point, and use the erase function to clear
|
|
76
|
+
the last drawing.
|
|
77
|
+
Reasonably use these two functions in an operation process to
|
|
78
|
+
achieve real-time progress display effect.
|
|
79
|
+
"""
|
|
80
|
+
process_bar.draw()
|
|
81
|
+
process_bar.erase()
|
|
82
|
+
```
|
|
83
|
+
## Detailed Documentation
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
For more detailed explanation documents, please visit the link: [Detail Doc ](https://#) .
|
|
87
|
+
## Function Features
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
- It can run normally on systems that support
|
|
91
|
+
[ANSI escape sequences](https://baike.baidu.com/item/ANSI转义序列/22735729?fr=ge_ala).
|
|
92
|
+
- When it encounters an exception during operation,
|
|
93
|
+
it will uniformly throw the `_CError` exception class
|
|
94
|
+
in CError, which is inherited from `Exception`.
|
|
95
|
+
- It supports most common colors, including red, yellow,
|
|
96
|
+
blue, green, cyan, purple, and gray. At the same time,
|
|
97
|
+
it also supports [RGB color](https://baike.baidu.com/item/RGB/342517?fr=ge_ala) codes to create objects
|
|
98
|
+
of the `Color` class in CColor. For specific operations,
|
|
99
|
+
please refer to the [Detailed Documentation](#detailed-documentation).
|
|
100
|
+
- It supports other text styles besides text color, such
|
|
101
|
+
as **bold**, *italic*, <u>underline</u>, ~~middleline~~, etc.
|
|
102
|
+
- For other features, please refer to the
|
|
103
|
+
[Detail Documentation](#detailed-documentation).
|
|
104
|
+
## Developer Contact Information
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
**RestRegular**
|
|
108
|
+
|
|
109
|
+
**email**: [3228097751@qq.com](https://www.qq.com)
|
|
110
|
+
|
|
111
|
+
**GitHub**: [RestRegular](https://github.com/RestRegular)
|
|
112
|
+
## Known Issues and Limitations
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
At present, the function of quickly building a table in
|
|
116
|
+
the console has been initially completed, but it is still
|
|
117
|
+
immature. **The known problem is that cells cannot span rows.**
|
|
118
|
+
<p style="color: red; font-style: italic;">
|
|
119
|
+
Warning: Do not use the row-spanning function in the table.
|
|
120
|
+
</p>
|
|
121
|
+
|
|
122
|
+
## Version _NewRcc-0.1.4_
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
**Contents of This Version Update**
|
|
126
|
+
1. A _README.md_ file has been added.
|
|
127
|
+
2. A project logo has been added.
|
|
128
|
+
3. Some potential problems have been found and marked in the README.md file.
|
|
129
|
+
4. A display error of README.md file has been fixed.
|
|
130
|
+
|
|
131
|
+
## Author
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
**RestRegular**
|
|
135
|
+
|
|
136
|
+
## Special Thanks
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
Waiting for occupancy. ^_^
|
|
140
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
newrcc
|
newrcc-0.5.1/setup.cfg
ADDED
newrcc-0.5.1/setup.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
with open(os.path.join(os.path.dirname(__file__), 'README.md'), encoding='utf-8') as f:
|
|
5
|
+
long_description = f.read()
|
|
6
|
+
|
|
7
|
+
setup(
|
|
8
|
+
name='newrcc',
|
|
9
|
+
version='0.5.1',
|
|
10
|
+
packages=find_packages(),
|
|
11
|
+
include_package_data=True,
|
|
12
|
+
install_requires= [],
|
|
13
|
+
author='RestRegular',
|
|
14
|
+
author_email='3228097751@qq.com',
|
|
15
|
+
description='A tool that can make your console output beautiful.',
|
|
16
|
+
long_description=long_description,
|
|
17
|
+
long_description_content_type='text/markdown',
|
|
18
|
+
classifiers=[
|
|
19
|
+
'Programming Language :: Python :: 3',
|
|
20
|
+
'License :: OSI Approved :: MIT License',
|
|
21
|
+
'Operating System :: OS Independent',
|
|
22
|
+
]
|
|
23
|
+
)
|