ttykit 0.2.2__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.
- ttykit-0.2.2/LICENSE +21 -0
- ttykit-0.2.2/PKG-INFO +99 -0
- ttykit-0.2.2/README.md +61 -0
- ttykit-0.2.2/pyproject.toml +31 -0
- ttykit-0.2.2/setup.cfg +4 -0
- ttykit-0.2.2/src/ttykit/__init__.py +22 -0
- ttykit-0.2.2/src/ttykit/_state.py +179 -0
- ttykit-0.2.2/src/ttykit/progress.py +85 -0
- ttykit-0.2.2/src/ttykit/spinner.py +13 -0
- ttykit-0.2.2/src/ttykit/status.py +103 -0
- ttykit-0.2.2/src/ttykit.egg-info/PKG-INFO +99 -0
- ttykit-0.2.2/src/ttykit.egg-info/SOURCES.txt +14 -0
- ttykit-0.2.2/src/ttykit.egg-info/dependency_links.txt +1 -0
- ttykit-0.2.2/src/ttykit.egg-info/entry_points.txt +2 -0
- ttykit-0.2.2/src/ttykit.egg-info/requires.txt +3 -0
- ttykit-0.2.2/src/ttykit.egg-info/top_level.txt +1 -0
ttykit-0.2.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 _STALIN_
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
ttykit-0.2.2/PKG-INFO
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ttykit
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: Helping made beatiful out in terminal
|
|
5
|
+
Author: He-STALIN
|
|
6
|
+
Author-email: hene.stalin@gmail.com
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 _STALIN_
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: Homepage, https://github.com/He-STALIN/ttykit
|
|
30
|
+
Project-URL: BugTracker, https://github.com/He-STALIN/ttykit/issues
|
|
31
|
+
Keywords: tty,terminal,formatting
|
|
32
|
+
Requires-Python: >=3.13
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Provides-Extra: test
|
|
36
|
+
Requires-Dist: pytest; extra == "test"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
<div align="center">
|
|
40
|
+
|
|
41
|
+
# TTYKit
|
|
42
|
+
|
|
43
|
+
> **Helping made beautiful out in terminal**
|
|
44
|
+
|
|
45
|
+
[](https://python.org)
|
|
46
|
+
[](LICENSE)
|
|
47
|
+
[](https://github.com/He-STALIN/ttykit)
|
|
48
|
+
|
|
49
|
+
</div>
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 📦 For Start
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
git clone https://github.com/He-STALIN/ttykit.git
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- Change dir and exec
|
|
59
|
+
```bash
|
|
60
|
+
pip install .
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- And use in your projects!
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
- This lib uploading with MIT License [See License](LICENSE)
|
|
67
|
+
|
|
68
|
+
## Code Examples
|
|
69
|
+
|
|
70
|
+
### Status
|
|
71
|
+
```python
|
|
72
|
+
from ttykit import Status, TaskState
|
|
73
|
+
|
|
74
|
+
with Status("Something unit", spinner="line") as status:
|
|
75
|
+
<some action>
|
|
76
|
+
status.set_state(TaskState.SUCCESS)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Progress
|
|
80
|
+
```python
|
|
81
|
+
from ttykit import Progress
|
|
82
|
+
|
|
83
|
+
with Progress(100, "Some desc", 40) as progress:
|
|
84
|
+
<some action>
|
|
85
|
+
progress.update(<value>)
|
|
86
|
+
<some action again>
|
|
87
|
+
progress.finish()
|
|
88
|
+
```
|
|
89
|
+
or
|
|
90
|
+
```python
|
|
91
|
+
with Progress(100, "Some desc", 40) as progress:
|
|
92
|
+
while not progress.finished:
|
|
93
|
+
<some actions>
|
|
94
|
+
progress.advance(<step>)
|
|
95
|
+
<maybe action again>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Also
|
|
99
|
+
- also you can use prepared colors in this lib
|
ttykit-0.2.2/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# TTYKit
|
|
4
|
+
|
|
5
|
+
> **Helping made beautiful out in terminal**
|
|
6
|
+
|
|
7
|
+
[](https://python.org)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](https://github.com/He-STALIN/ttykit)
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 📦 For Start
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
git clone https://github.com/He-STALIN/ttykit.git
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- Change dir and exec
|
|
21
|
+
```bash
|
|
22
|
+
pip install .
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
- And use in your projects!
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
- This lib uploading with MIT License [See License](LICENSE)
|
|
29
|
+
|
|
30
|
+
## Code Examples
|
|
31
|
+
|
|
32
|
+
### Status
|
|
33
|
+
```python
|
|
34
|
+
from ttykit import Status, TaskState
|
|
35
|
+
|
|
36
|
+
with Status("Something unit", spinner="line") as status:
|
|
37
|
+
<some action>
|
|
38
|
+
status.set_state(TaskState.SUCCESS)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Progress
|
|
42
|
+
```python
|
|
43
|
+
from ttykit import Progress
|
|
44
|
+
|
|
45
|
+
with Progress(100, "Some desc", 40) as progress:
|
|
46
|
+
<some action>
|
|
47
|
+
progress.update(<value>)
|
|
48
|
+
<some action again>
|
|
49
|
+
progress.finish()
|
|
50
|
+
```
|
|
51
|
+
or
|
|
52
|
+
```python
|
|
53
|
+
with Progress(100, "Some desc", 40) as progress:
|
|
54
|
+
while not progress.finished:
|
|
55
|
+
<some actions>
|
|
56
|
+
progress.advance(<step>)
|
|
57
|
+
<maybe action again>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Also
|
|
61
|
+
- also you can use prepared colors in this lib
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=80.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[tool.setuptools.packages.find]
|
|
6
|
+
where = ["src"]
|
|
7
|
+
include = ["ttykit*"]
|
|
8
|
+
|
|
9
|
+
[project]
|
|
10
|
+
name = "ttykit"
|
|
11
|
+
version = "0.2.2"
|
|
12
|
+
description = "Helping made beatiful out in terminal"
|
|
13
|
+
requires-python = ">=3.13"
|
|
14
|
+
authors = [
|
|
15
|
+
{ name = "He-STALIN"},
|
|
16
|
+
{email = "hene.stalin@gmail.com"}
|
|
17
|
+
]
|
|
18
|
+
license = {file = "LICENSE"}
|
|
19
|
+
readme = "README.md"
|
|
20
|
+
keywords = ['tty', 'terminal', 'formatting']
|
|
21
|
+
dependencies = []
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
ttykit-spinner = "ttykit.spinner:main"
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
test = ["pytest"]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/He-STALIN/ttykit"
|
|
31
|
+
BugTracker = "https://github.com/He-STALIN/ttykit/issues"
|
ttykit-0.2.2/setup.cfg
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Helping made beatiful out in terminal"""
|
|
2
|
+
|
|
3
|
+
from .progress import Progress
|
|
4
|
+
from .status import Status
|
|
5
|
+
from ._state import TaskState, Colors, Styles, RESET
|
|
6
|
+
|
|
7
|
+
__colors__ = [
|
|
8
|
+
Colors,
|
|
9
|
+
Styles,
|
|
10
|
+
RESET
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
'Progress',
|
|
15
|
+
'Status',
|
|
16
|
+
'TaskState'
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
__name__ = 'ttykit'
|
|
20
|
+
__author__ = 'He-STALIN'
|
|
21
|
+
__version__ = '0.2.2'
|
|
22
|
+
__license__ = 'MIT'
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
class Colors:
|
|
4
|
+
"""Applied colors for text in the terminal. Can be mixed with `class Style`"""
|
|
5
|
+
BLACK = "\033[30m"
|
|
6
|
+
RED = "\033[31m"
|
|
7
|
+
GREEN = "\033[32m"
|
|
8
|
+
YELLOW = "\033[33m"
|
|
9
|
+
BLUE = "\033[34m"
|
|
10
|
+
PURPLE = "\033[35m"
|
|
11
|
+
CYAN = "\033[36m"
|
|
12
|
+
WHITE = "\033[37m"
|
|
13
|
+
|
|
14
|
+
DARK_GREY = "\033[90m"
|
|
15
|
+
LIGHT_RED = "\033[91m"
|
|
16
|
+
LIGHT_GREEN = "\033[92m"
|
|
17
|
+
LIGHT_YELLOW = "\033[93m"
|
|
18
|
+
LIGHT_BLUE = "\033[94m"
|
|
19
|
+
LIGHT_PURPLE = "\033[95m"
|
|
20
|
+
LIGHT_CYAN = "\033[96m"
|
|
21
|
+
LIGHT_WHITE = "\033[97m"
|
|
22
|
+
RESET = "\033[0m"
|
|
23
|
+
|
|
24
|
+
class Styles:
|
|
25
|
+
"""Applied styles for text in the terminal. Can be mixed with `class Colors`"""
|
|
26
|
+
RESET = "\033[0m"
|
|
27
|
+
BOLD = "\033[1m"
|
|
28
|
+
DIM = "\033[2m"
|
|
29
|
+
ITALIC = "\033[3m"
|
|
30
|
+
UNDERLINE = "\033[4m"
|
|
31
|
+
BLINK = "\033[5m"
|
|
32
|
+
RAPID_BLINK = "\033[6m"
|
|
33
|
+
REVERSE = "\033[7m"
|
|
34
|
+
STRIKETHROUGH = "\033[9m"
|
|
35
|
+
|
|
36
|
+
RESET = "\033[0m"
|
|
37
|
+
|
|
38
|
+
class TaskState(Enum):
|
|
39
|
+
RUNNING = "running"
|
|
40
|
+
SUCCESS = "success"
|
|
41
|
+
ERROR = "error"
|
|
42
|
+
WARNING = "warning"
|
|
43
|
+
|
|
44
|
+
STATUS_ANIMATION = {
|
|
45
|
+
'bar': ["[ ]",
|
|
46
|
+
"[= ]",
|
|
47
|
+
"[== ]",
|
|
48
|
+
f"[{Colors.RED}*{RESET}== ]",
|
|
49
|
+
f"[={Colors.RED}*{RESET}== ]",
|
|
50
|
+
f"[=={Colors.RED}*{RESET}== ]",
|
|
51
|
+
f"[ =={Colors.RED}*{RESET}==]",
|
|
52
|
+
f"[ =={Colors.RED}*{RESET}=]",
|
|
53
|
+
f"[ =={Colors.RED}*{RESET}]",
|
|
54
|
+
"[ ==]",
|
|
55
|
+
"[ =]",
|
|
56
|
+
"[ ]"
|
|
57
|
+
],
|
|
58
|
+
'ball':["(● )",
|
|
59
|
+
"( ● )",
|
|
60
|
+
"( ● )",
|
|
61
|
+
"( ● )",
|
|
62
|
+
"( ● )",
|
|
63
|
+
"( ●)",
|
|
64
|
+
"( ● )",
|
|
65
|
+
"( ● )",
|
|
66
|
+
"( ● )",
|
|
67
|
+
"( ● )"
|
|
68
|
+
],
|
|
69
|
+
'dots': ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
|
|
70
|
+
'dots12': ["⢀⠀",
|
|
71
|
+
"⡀⠀",
|
|
72
|
+
"⠄⠀",
|
|
73
|
+
"⢂⠀",
|
|
74
|
+
"⡂⠀",
|
|
75
|
+
"⠅⠀",
|
|
76
|
+
"⢃⠀",
|
|
77
|
+
"⡃⠀",
|
|
78
|
+
"⠍⠀",
|
|
79
|
+
"⢋⠀",
|
|
80
|
+
"⡋⠀",
|
|
81
|
+
"⠍⠁",
|
|
82
|
+
"⢋⠁",
|
|
83
|
+
"⡋⠁",
|
|
84
|
+
"⠍⠉",
|
|
85
|
+
"⠋⠉",
|
|
86
|
+
"⠋⠉",
|
|
87
|
+
"⠉⠙",
|
|
88
|
+
"⠉⠙",
|
|
89
|
+
"⠉⠩",
|
|
90
|
+
"⠈⢙",
|
|
91
|
+
"⠈⡙",
|
|
92
|
+
"⢈⠩",
|
|
93
|
+
"⡀⢙",
|
|
94
|
+
"⠄⡙",
|
|
95
|
+
"⢂⠩",
|
|
96
|
+
"⡂⢘",
|
|
97
|
+
"⠅⡘",
|
|
98
|
+
"⢃⠨",
|
|
99
|
+
"⡃⢐",
|
|
100
|
+
"⠍⡐",
|
|
101
|
+
"⢋⠠",
|
|
102
|
+
"⡋⢀",
|
|
103
|
+
"⠍⡁",
|
|
104
|
+
"⢋⠁",
|
|
105
|
+
"⡋⠁",
|
|
106
|
+
"⠍⠉",
|
|
107
|
+
"⠋⠉",
|
|
108
|
+
"⠋⠉",
|
|
109
|
+
"⠉⠙",
|
|
110
|
+
"⠉⠙",
|
|
111
|
+
"⠉⠩",
|
|
112
|
+
"⠈⢙",
|
|
113
|
+
"⠈⡙",
|
|
114
|
+
"⠈⠩",
|
|
115
|
+
"⠀⢙",
|
|
116
|
+
"⠀⡙",
|
|
117
|
+
"⠀⠩",
|
|
118
|
+
"⠀⢘",
|
|
119
|
+
"⠀⡘",
|
|
120
|
+
"⠀⠨",
|
|
121
|
+
"⠀⢐",
|
|
122
|
+
"⠀⡐",
|
|
123
|
+
"⠀⠠",
|
|
124
|
+
"⠀⢀",
|
|
125
|
+
"⠀⡀"
|
|
126
|
+
],
|
|
127
|
+
'bouncingBar': ["[ ]",
|
|
128
|
+
"[= ]",
|
|
129
|
+
"[== ]",
|
|
130
|
+
f"[{Colors.RED}*{RESET}== ]",
|
|
131
|
+
f"[={Colors.RED}*{RESET}== ]",
|
|
132
|
+
f"[=={Colors.RED}*{RESET}== ]",
|
|
133
|
+
f"[ =={Colors.RED}*{RESET}==]",
|
|
134
|
+
f"[ =={Colors.RED}*{RESET}=]",
|
|
135
|
+
f"[ =={Colors.RED}*{RESET}]",
|
|
136
|
+
"[ ==]",
|
|
137
|
+
"[ =]",
|
|
138
|
+
"[ ]",
|
|
139
|
+
"[ =]",
|
|
140
|
+
"[ ==]",
|
|
141
|
+
f"[ =={Colors.RED}*{RESET}]",
|
|
142
|
+
f"[ =={Colors.RED}*{RESET}=]",
|
|
143
|
+
f"[ =={Colors.RED}*{RESET}==]",
|
|
144
|
+
f"[=={Colors.RED}*{RESET}== ]",
|
|
145
|
+
f"[={Colors.RED}*{RESET}== ]",
|
|
146
|
+
f"[{Colors.RED}*{RESET}== ]",
|
|
147
|
+
"[== ]",
|
|
148
|
+
"[= ]",
|
|
149
|
+
"[ ]"
|
|
150
|
+
],
|
|
151
|
+
'points': ["∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"],
|
|
152
|
+
'wave': [" ~ ", " ≈ ", " ≈≈", "≈≈≈", "≈≈ ", " ≈ ", " ~ "],
|
|
153
|
+
'pulse': [" • ", " ••", "•••", "•• ", " • "],
|
|
154
|
+
'moon': ["🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘"],
|
|
155
|
+
'clock':["🕐", "🕑", "🕒", "🕓", "🕔", "🕕", "🕖", "🕗", "🕘", "🕙", "🕚", "🕛"],
|
|
156
|
+
'snake': ["➡", "⬆", "⬅", "⬇"],
|
|
157
|
+
'line': ["|", "/", "-", "\\"],
|
|
158
|
+
'box': ["▖", "▘", "▝", "▗"],
|
|
159
|
+
'arc': ["◜", "◠", "◝", "◞", "◡", "◟"]
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
BARS = {
|
|
163
|
+
'line': {
|
|
164
|
+
"filled": f"{Colors.LIGHT_PURPLE}━{RESET}",
|
|
165
|
+
"bg": f"{Colors.DARK_GREY}━{RESET}"
|
|
166
|
+
},
|
|
167
|
+
'points': {
|
|
168
|
+
"filled": "●",
|
|
169
|
+
"bg": f"{Colors.DARK_GREY}○{RESET}"
|
|
170
|
+
},
|
|
171
|
+
'blocks': {
|
|
172
|
+
"filled": "█",
|
|
173
|
+
"bg": "░"
|
|
174
|
+
},
|
|
175
|
+
"arrow": {
|
|
176
|
+
"filled": f"{Colors.GREEN}═{RESET}",
|
|
177
|
+
"bg": f"{Colors.DARK_GREY}-{RESET}"
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from ._state import *
|
|
3
|
+
|
|
4
|
+
class Progress:
|
|
5
|
+
"""
|
|
6
|
+
Creating Custom Loading Bar in the terminal
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
total (int): max value of bar. Default: 100
|
|
10
|
+
prefix (str): some description of bar. Can be empty
|
|
11
|
+
bar_length (int): how many characters in bar length. Default: 30
|
|
12
|
+
bar_style: bar performance style. Default: `line`. Avaliable styles: `line`, `points`, `blocks`, `arrow`.
|
|
13
|
+
frames (bool): use bracket or not. Default: False
|
|
14
|
+
Returns:
|
|
15
|
+
None: write in the terminal
|
|
16
|
+
Examples:
|
|
17
|
+
### realization:
|
|
18
|
+
```python
|
|
19
|
+
from ttykit import CustomProgress
|
|
20
|
+
|
|
21
|
+
with CustomProgress(total=50, prefix="Loading", bar_length=100) as progress:
|
|
22
|
+
while not progress.finished:
|
|
23
|
+
# <some action>
|
|
24
|
+
progress.advance(2)
|
|
25
|
+
if progress.current >= 20:
|
|
26
|
+
progress.stop() # Force stopping bar & exit
|
|
27
|
+
```
|
|
28
|
+
### out:
|
|
29
|
+
```
|
|
30
|
+
Loading ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 40%
|
|
31
|
+
```
|
|
32
|
+
"""
|
|
33
|
+
def __init__(self, total: int=100, prefix: str=None, bar_length: int=30, bar_style='line', frames: bool=False):
|
|
34
|
+
self.total = total
|
|
35
|
+
self.prefix = prefix if prefix else ""
|
|
36
|
+
self.bar_length = bar_length
|
|
37
|
+
self.frames = frames
|
|
38
|
+
temp = BARS.get(bar_style)
|
|
39
|
+
self.bar_filled = temp['filled']
|
|
40
|
+
self.bar_bg = temp['bg']
|
|
41
|
+
self.current = 0
|
|
42
|
+
self.finished = False
|
|
43
|
+
|
|
44
|
+
def __enter__(self):
|
|
45
|
+
return self
|
|
46
|
+
|
|
47
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
48
|
+
if not self.finished:
|
|
49
|
+
self.finish()
|
|
50
|
+
|
|
51
|
+
def update(self, value):
|
|
52
|
+
if not self.finished:
|
|
53
|
+
self.current = min(value, self.total)
|
|
54
|
+
self._render()
|
|
55
|
+
|
|
56
|
+
def advance(self, step: int=1):
|
|
57
|
+
"""
|
|
58
|
+
increase state on some steps
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
step (int): count of step. Default: 1
|
|
62
|
+
"""
|
|
63
|
+
self.update(self.current + step)
|
|
64
|
+
|
|
65
|
+
def _render(self):
|
|
66
|
+
percent = int(self.current / self.total * 100)
|
|
67
|
+
filled = int(self.current / self.total * self.bar_length)
|
|
68
|
+
bar = str(self.bar_filled) * filled + str(self.bar_bg) * (self.bar_length - filled)
|
|
69
|
+
sys.stdout.write(f"\r{self.prefix} {"[ " if self.frames else ""}{bar}{" ]" if self.frames else ""} {percent}%")
|
|
70
|
+
sys.stdout.flush()
|
|
71
|
+
|
|
72
|
+
def stop(self):
|
|
73
|
+
"""
|
|
74
|
+
Force stopping bar and exiting
|
|
75
|
+
"""
|
|
76
|
+
print()
|
|
77
|
+
self.finished = True
|
|
78
|
+
|
|
79
|
+
def finish(self):
|
|
80
|
+
"""
|
|
81
|
+
Set 100% and exiting
|
|
82
|
+
"""
|
|
83
|
+
self.update(self.total)
|
|
84
|
+
print()
|
|
85
|
+
self.finished = True
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from .status import Status, TaskState
|
|
3
|
+
from ._state import STATUS_ANIMATION
|
|
4
|
+
|
|
5
|
+
def show_all_spinners():
|
|
6
|
+
for name in STATUS_ANIMATION.keys():
|
|
7
|
+
print(f"-==[ {name} ]==-")
|
|
8
|
+
with Status("Test", spinner=name) as status:
|
|
9
|
+
time.sleep(2)
|
|
10
|
+
status.set_state(TaskState.SUCCESS)
|
|
11
|
+
|
|
12
|
+
if __name__ == "__main__":
|
|
13
|
+
show_all_spinners()
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
from threading import Thread
|
|
2
|
+
import time
|
|
3
|
+
import sys
|
|
4
|
+
from ._state import *
|
|
5
|
+
|
|
6
|
+
class Status:
|
|
7
|
+
"""
|
|
8
|
+
Create animated status of task in the terminal
|
|
9
|
+
|
|
10
|
+
Args:
|
|
11
|
+
message (str): some description for task. Can't be empty
|
|
12
|
+
spinner: animation for task executing. Avaliable animations: `bar`, `ball` ... see all `python -m ttykit.spinner`
|
|
13
|
+
color: color of name of task unit. Default: cyan
|
|
14
|
+
Returns:
|
|
15
|
+
None: show task in the terminal
|
|
16
|
+
Examples:
|
|
17
|
+
### Realization:
|
|
18
|
+
```python
|
|
19
|
+
from ttykit import CustomStatus, TaskState
|
|
20
|
+
|
|
21
|
+
with CustomStatus("Unit Test 8", spinner="dots12") as status:
|
|
22
|
+
# <task1>
|
|
23
|
+
status.set_message("Unit Test 9")
|
|
24
|
+
# <task2>
|
|
25
|
+
status.set_state(TaskState.SUCCESS)
|
|
26
|
+
```
|
|
27
|
+
### out when task1
|
|
28
|
+
```
|
|
29
|
+
⠀⢙ Loading Unit Test 8
|
|
30
|
+
```
|
|
31
|
+
### out when task2
|
|
32
|
+
```
|
|
33
|
+
⢀⠀ Loading Unit Test 9
|
|
34
|
+
```
|
|
35
|
+
### out when finished
|
|
36
|
+
```
|
|
37
|
+
[ OK ] Loading Unit Test 9
|
|
38
|
+
```
|
|
39
|
+
"""
|
|
40
|
+
def __init__(self, message: str, spinner="bar", color="CYAN"):
|
|
41
|
+
self.message = message
|
|
42
|
+
self.color = color
|
|
43
|
+
self.spinner = spinner
|
|
44
|
+
self.state = TaskState.RUNNING
|
|
45
|
+
self.frames = STATUS_ANIMATION.get(self.spinner, STATUS_ANIMATION['bar'])
|
|
46
|
+
self.running = False
|
|
47
|
+
self.animation_thread = None
|
|
48
|
+
self.paused = False
|
|
49
|
+
|
|
50
|
+
def __enter__(self):
|
|
51
|
+
self.running = True
|
|
52
|
+
self._animate()
|
|
53
|
+
return self
|
|
54
|
+
|
|
55
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
56
|
+
self.running = False
|
|
57
|
+
time.sleep(0.1)
|
|
58
|
+
state_color = Colors.GREEN if self.state == TaskState.SUCCESS else Colors.RED if self.state == TaskState.ERROR else Colors.YELLOW
|
|
59
|
+
state_text = " OK " if self.state == TaskState.SUCCESS else " FAIL " if self.state == TaskState.ERROR else " WARN "
|
|
60
|
+
print(f"\r[{state_color}{state_text}{RESET}] Loading {self._get_color()}{self.message}{RESET}")
|
|
61
|
+
|
|
62
|
+
def _animate(self):
|
|
63
|
+
def run():
|
|
64
|
+
i = 0
|
|
65
|
+
while self.running:
|
|
66
|
+
if not self.paused:
|
|
67
|
+
frame = self.frames[i % len(self.frames)]
|
|
68
|
+
print(f"\r{frame} Loading {self._get_color()}{self.message}{RESET}", end="")
|
|
69
|
+
sys.stdout.flush()
|
|
70
|
+
i += 1
|
|
71
|
+
time.sleep(0.08)
|
|
72
|
+
self.animation_thread = Thread(target=run, daemon=True)
|
|
73
|
+
self.animation_thread.start()
|
|
74
|
+
|
|
75
|
+
def _get_color(self):
|
|
76
|
+
return (Colors.CYAN if self.color == "CYAN" else Colors.GREEN if self.color == "GREEN" else Colors.RED)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def set_message(self, new_message: str):
|
|
80
|
+
"""
|
|
81
|
+
Edit text of task when task running
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
new_message (str): new message of task status
|
|
85
|
+
"""
|
|
86
|
+
self.message = new_message
|
|
87
|
+
|
|
88
|
+
def set_state(self, state: TaskState):
|
|
89
|
+
"""
|
|
90
|
+
Set state of task
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
state (TaskState): Avaliable states: SUCCESS, ERROR, WARNING
|
|
94
|
+
"""
|
|
95
|
+
self.state = state
|
|
96
|
+
|
|
97
|
+
def pause(self):
|
|
98
|
+
"""Pause animation"""
|
|
99
|
+
self.paused = True
|
|
100
|
+
|
|
101
|
+
def resume(self):
|
|
102
|
+
"""Resume animation"""
|
|
103
|
+
self.paused = False
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ttykit
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: Helping made beatiful out in terminal
|
|
5
|
+
Author: He-STALIN
|
|
6
|
+
Author-email: hene.stalin@gmail.com
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 _STALIN_
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: Homepage, https://github.com/He-STALIN/ttykit
|
|
30
|
+
Project-URL: BugTracker, https://github.com/He-STALIN/ttykit/issues
|
|
31
|
+
Keywords: tty,terminal,formatting
|
|
32
|
+
Requires-Python: >=3.13
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Provides-Extra: test
|
|
36
|
+
Requires-Dist: pytest; extra == "test"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
<div align="center">
|
|
40
|
+
|
|
41
|
+
# TTYKit
|
|
42
|
+
|
|
43
|
+
> **Helping made beautiful out in terminal**
|
|
44
|
+
|
|
45
|
+
[](https://python.org)
|
|
46
|
+
[](LICENSE)
|
|
47
|
+
[](https://github.com/He-STALIN/ttykit)
|
|
48
|
+
|
|
49
|
+
</div>
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 📦 For Start
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
git clone https://github.com/He-STALIN/ttykit.git
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- Change dir and exec
|
|
59
|
+
```bash
|
|
60
|
+
pip install .
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- And use in your projects!
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
- This lib uploading with MIT License [See License](LICENSE)
|
|
67
|
+
|
|
68
|
+
## Code Examples
|
|
69
|
+
|
|
70
|
+
### Status
|
|
71
|
+
```python
|
|
72
|
+
from ttykit import Status, TaskState
|
|
73
|
+
|
|
74
|
+
with Status("Something unit", spinner="line") as status:
|
|
75
|
+
<some action>
|
|
76
|
+
status.set_state(TaskState.SUCCESS)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Progress
|
|
80
|
+
```python
|
|
81
|
+
from ttykit import Progress
|
|
82
|
+
|
|
83
|
+
with Progress(100, "Some desc", 40) as progress:
|
|
84
|
+
<some action>
|
|
85
|
+
progress.update(<value>)
|
|
86
|
+
<some action again>
|
|
87
|
+
progress.finish()
|
|
88
|
+
```
|
|
89
|
+
or
|
|
90
|
+
```python
|
|
91
|
+
with Progress(100, "Some desc", 40) as progress:
|
|
92
|
+
while not progress.finished:
|
|
93
|
+
<some actions>
|
|
94
|
+
progress.advance(<step>)
|
|
95
|
+
<maybe action again>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Also
|
|
99
|
+
- also you can use prepared colors in this lib
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/ttykit/__init__.py
|
|
5
|
+
src/ttykit/_state.py
|
|
6
|
+
src/ttykit/progress.py
|
|
7
|
+
src/ttykit/spinner.py
|
|
8
|
+
src/ttykit/status.py
|
|
9
|
+
src/ttykit.egg-info/PKG-INFO
|
|
10
|
+
src/ttykit.egg-info/SOURCES.txt
|
|
11
|
+
src/ttykit.egg-info/dependency_links.txt
|
|
12
|
+
src/ttykit.egg-info/entry_points.txt
|
|
13
|
+
src/ttykit.egg-info/requires.txt
|
|
14
|
+
src/ttykit.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ttykit
|