ttykit 0.4.0__tar.gz → 0.5.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.
- ttykit-0.5.0/PKG-INFO +189 -0
- ttykit-0.5.0/README.pypi.md +151 -0
- {ttykit-0.4.0 → ttykit-0.5.0}/pyproject.toml +4 -3
- ttykit-0.5.0/src/ttykit/__init__.py +65 -0
- {ttykit-0.4.0 → ttykit-0.5.0}/src/ttykit/console/TUI.py +3 -2
- {ttykit-0.4.0 → ttykit-0.5.0}/src/ttykit/console/console.py +58 -16
- ttykit-0.5.0/src/ttykit/console/input/__init__.py +90 -0
- ttykit-0.5.0/src/ttykit/console/input/_local.py +39 -0
- ttykit-0.5.0/src/ttykit/console/input/_unix.py +161 -0
- ttykit-0.5.0/src/ttykit/console/input/_windows.py +249 -0
- ttykit-0.5.0/src/ttykit/data/__init__.py +15 -0
- {ttykit-0.4.0/src/ttykit → ttykit-0.5.0/src/ttykit/data}/_state.py +1 -1
- ttykit-0.5.0/src/ttykit/data/const.py +263 -0
- ttykit-0.5.0/src/ttykit/data/dataclass.py +13 -0
- ttykit-0.5.0/src/ttykit/examples/progressbar.py +14 -0
- {ttykit-0.4.0 → ttykit-0.5.0}/src/ttykit/examples/spinner.py +1 -1
- {ttykit-0.4.0 → ttykit-0.5.0}/src/ttykit/progress.py +11 -7
- {ttykit-0.4.0 → ttykit-0.5.0}/src/ttykit/segmentation.py +1 -1
- {ttykit-0.4.0 → ttykit-0.5.0}/src/ttykit/status.py +20 -16
- {ttykit-0.4.0 → ttykit-0.5.0}/src/ttykit/tree.py +4 -4
- ttykit-0.5.0/src/ttykit/utils/__init__.py +16 -0
- ttykit-0.5.0/src/ttykit/utils/exceptions.py +18 -0
- ttykit-0.5.0/src/ttykit/utils/utils.py +38 -0
- ttykit-0.5.0/src/ttykit/utils/warnings.py +8 -0
- ttykit-0.5.0/src/ttykit.egg-info/PKG-INFO +189 -0
- ttykit-0.5.0/src/ttykit.egg-info/SOURCES.txt +31 -0
- {ttykit-0.4.0 → ttykit-0.5.0}/src/ttykit.egg-info/entry_points.txt +1 -0
- {ttykit-0.4.0 → ttykit-0.5.0}/src/ttykit.egg-info/requires.txt +0 -1
- ttykit-0.4.0/PKG-INFO +0 -117
- ttykit-0.4.0/src/ttykit/__init__.py +0 -73
- ttykit-0.4.0/src/ttykit/console/const.py +0 -18
- ttykit-0.4.0/src/ttykit.egg-info/PKG-INFO +0 -117
- ttykit-0.4.0/src/ttykit.egg-info/SOURCES.txt +0 -19
- {ttykit-0.4.0 → ttykit-0.5.0}/LICENSE +0 -0
- {ttykit-0.4.0 → ttykit-0.5.0}/README.md +0 -0
- {ttykit-0.4.0 → ttykit-0.5.0}/setup.cfg +0 -0
- {ttykit-0.4.0 → ttykit-0.5.0}/src/ttykit.egg-info/dependency_links.txt +0 -0
- {ttykit-0.4.0 → ttykit-0.5.0}/src/ttykit.egg-info/top_level.txt +0 -0
ttykit-0.5.0/PKG-INFO
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ttykit
|
|
3
|
+
Version: 0.5.0
|
|
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
|
+
[](https://github.com/He-STALIN/ttykit/blob/main/LICENSE)
|
|
47
|
+
[](https://github.com/He-STALIN/ttykit)
|
|
48
|
+
[](https://pypi.org/project/ttykit/)
|
|
49
|
+
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
## This file is 2-lang
|
|
53
|
+
- [EN Version](#en)
|
|
54
|
+
- [RU Версия](#ru)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## EN
|
|
58
|
+
### For Start
|
|
59
|
+
- #### Automatic
|
|
60
|
+
- exec `pip install ttykit`
|
|
61
|
+
|
|
62
|
+
- #### Manually
|
|
63
|
+
- #### Dev version
|
|
64
|
+
- clone repository
|
|
65
|
+
```bash
|
|
66
|
+
git clone https://github.com/He-STALIN/ttykit.git
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- change to dir and exec
|
|
70
|
+
```bash
|
|
71
|
+
pip install .
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- #### From Release
|
|
75
|
+
- download any release from [Releases](https://github.com/He-STALIN/ttykit/releases)
|
|
76
|
+
|
|
77
|
+
- exec in terminal
|
|
78
|
+
```bash
|
|
79
|
+
pip install <path>
|
|
80
|
+
```
|
|
81
|
+
where `<path>` you need write path to the downloaded release file
|
|
82
|
+
|
|
83
|
+
### support the project
|
|
84
|
+
- If you would like the project to continue developing, you can make a [donation](https://yoomoney.ru/to/4100118618732284/100).
|
|
85
|
+
- Account: `4100 1186 1873 2284` (YouMoney)
|
|
86
|
+
- or
|
|
87
|
+
- Find bugs in the library and report them in the [`issues` section on GitHub](https://github.com/He-STALIN/ttykit/issues).
|
|
88
|
+
|
|
89
|
+
### Code Examples
|
|
90
|
+
- #### Status
|
|
91
|
+
```python
|
|
92
|
+
from ttykit import Status, TaskState
|
|
93
|
+
|
|
94
|
+
with Status("Something unit", spinner="line") as status:
|
|
95
|
+
... # your payload
|
|
96
|
+
status.set_state(TaskState.SUCCESS)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
- #### Progress
|
|
100
|
+
```python
|
|
101
|
+
from ttykit import Progress
|
|
102
|
+
|
|
103
|
+
with Progress(100, "Some desc", 40) as progress:
|
|
104
|
+
... # your code
|
|
105
|
+
progress.update(value)
|
|
106
|
+
... # your code again
|
|
107
|
+
progress.finish()
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
- **for more code examples see** [CODE USE](https://github.com/He-STALIN/ttykit/blob/main/docs/en/CODE_USE.md)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
### License
|
|
114
|
+
- This lib uploading with MIT License. [See License](https://github.com/He-STALIN/ttykit/blob/main/LICENSE)
|
|
115
|
+
|
|
116
|
+
### Versions
|
|
117
|
+
- You interesting see versions? You can see [CHANGELOG](https://github.com/He-STALIN/ttykit/blob/main/docs/en/CHANGELOG.md)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
## RU
|
|
121
|
+
### Для начала использования
|
|
122
|
+
- #### Авто-установка
|
|
123
|
+
- выполните `pip install ttykit` в терминале
|
|
124
|
+
|
|
125
|
+
- #### Вручную
|
|
126
|
+
- #### Разрабатываемую версию
|
|
127
|
+
- скопируйте репозиторий
|
|
128
|
+
```bash
|
|
129
|
+
git clone https://github.com/He-STALIN/ttykit.git
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
- перейдите в папку и выполни
|
|
133
|
+
```bash
|
|
134
|
+
pip install .
|
|
135
|
+
```
|
|
136
|
+
- #### Релизную версию
|
|
137
|
+
- Скачайте любой релиз из вкладки ["Releases"](https://github.com/He-STALIN/ttykit/releases)
|
|
138
|
+
|
|
139
|
+
- выполните в терминале
|
|
140
|
+
```bash
|
|
141
|
+
pip install <path>
|
|
142
|
+
```
|
|
143
|
+
Где `<path>` вам нужно вставить путь к скачанному файлу релиза
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
### Поддержите проект
|
|
147
|
+
- Если вы желаете, чтобы проект разрабатывался дальше, вы можете сделать [пожертвование](https://yoomoney.ru/to/4100118618732284/100).
|
|
148
|
+
- Счет: `4100 1186 1873 2284` (ЮМани)
|
|
149
|
+
- или
|
|
150
|
+
- Ищите ошибки в библиотеке и сообщайте о них в [`issues` на GitHub](https://github.com/He-STALIN/ttykit/issues).
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
### Примеры кода
|
|
154
|
+
- #### Status класс
|
|
155
|
+
```python
|
|
156
|
+
from ttykit import Status, TaskState
|
|
157
|
+
|
|
158
|
+
with Status("Какая-то задача", spinner="line") as status:
|
|
159
|
+
... # ваша нагрузка
|
|
160
|
+
status.set_state(TaskState.SUCCESS)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
- #### Progress класс
|
|
164
|
+
```python
|
|
165
|
+
from ttykit import Progress
|
|
166
|
+
|
|
167
|
+
with Progress(100, "Некоторое описание", 40) as progress:
|
|
168
|
+
... # ваш код
|
|
169
|
+
progress.update(value)
|
|
170
|
+
... # и снова ваш код
|
|
171
|
+
progress.finish()
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
- **Для большего количества примеров и описания смотрите** [CODE USE](https://github.com/He-STALIN/ttykit/blob/main/docs/ru/CODE_USE.md)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
### Лицензия
|
|
178
|
+
- Это библиотека распространяется под лицензией MIT. [Смотреть лицензию](https://github.com/He-STALIN/ttykit/blob/main/LICENSE)
|
|
179
|
+
|
|
180
|
+
### Версии
|
|
181
|
+
- вам интересно узнать про версии? Вы можете посмотреть [CHANGELOG](https://github.com/He-STALIN/ttykit/blob/main/docs/ru/CHANGELOG.md)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
<div align="center">
|
|
186
|
+
|
|
187
|
+
*ttykit by He_STALIN. All rights reserved*
|
|
188
|
+
|
|
189
|
+
</div>
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# TTYKit
|
|
4
|
+
|
|
5
|
+
> **Helping made beautiful out in terminal**
|
|
6
|
+
|
|
7
|
+
[](https://python.org)
|
|
8
|
+
[](https://github.com/He-STALIN/ttykit/blob/main/LICENSE)
|
|
9
|
+
[](https://github.com/He-STALIN/ttykit)
|
|
10
|
+
[](https://pypi.org/project/ttykit/)
|
|
11
|
+
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
## This file is 2-lang
|
|
15
|
+
- [EN Version](#en)
|
|
16
|
+
- [RU Версия](#ru)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## EN
|
|
20
|
+
### For Start
|
|
21
|
+
- #### Automatic
|
|
22
|
+
- exec `pip install ttykit`
|
|
23
|
+
|
|
24
|
+
- #### Manually
|
|
25
|
+
- #### Dev version
|
|
26
|
+
- clone repository
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/He-STALIN/ttykit.git
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- change to dir and exec
|
|
32
|
+
```bash
|
|
33
|
+
pip install .
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- #### From Release
|
|
37
|
+
- download any release from [Releases](https://github.com/He-STALIN/ttykit/releases)
|
|
38
|
+
|
|
39
|
+
- exec in terminal
|
|
40
|
+
```bash
|
|
41
|
+
pip install <path>
|
|
42
|
+
```
|
|
43
|
+
where `<path>` you need write path to the downloaded release file
|
|
44
|
+
|
|
45
|
+
### support the project
|
|
46
|
+
- If you would like the project to continue developing, you can make a [donation](https://yoomoney.ru/to/4100118618732284/100).
|
|
47
|
+
- Account: `4100 1186 1873 2284` (YouMoney)
|
|
48
|
+
- or
|
|
49
|
+
- Find bugs in the library and report them in the [`issues` section on GitHub](https://github.com/He-STALIN/ttykit/issues).
|
|
50
|
+
|
|
51
|
+
### Code Examples
|
|
52
|
+
- #### Status
|
|
53
|
+
```python
|
|
54
|
+
from ttykit import Status, TaskState
|
|
55
|
+
|
|
56
|
+
with Status("Something unit", spinner="line") as status:
|
|
57
|
+
... # your payload
|
|
58
|
+
status.set_state(TaskState.SUCCESS)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- #### Progress
|
|
62
|
+
```python
|
|
63
|
+
from ttykit import Progress
|
|
64
|
+
|
|
65
|
+
with Progress(100, "Some desc", 40) as progress:
|
|
66
|
+
... # your code
|
|
67
|
+
progress.update(value)
|
|
68
|
+
... # your code again
|
|
69
|
+
progress.finish()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- **for more code examples see** [CODE USE](https://github.com/He-STALIN/ttykit/blob/main/docs/en/CODE_USE.md)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
### License
|
|
76
|
+
- This lib uploading with MIT License. [See License](https://github.com/He-STALIN/ttykit/blob/main/LICENSE)
|
|
77
|
+
|
|
78
|
+
### Versions
|
|
79
|
+
- You interesting see versions? You can see [CHANGELOG](https://github.com/He-STALIN/ttykit/blob/main/docs/en/CHANGELOG.md)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## RU
|
|
83
|
+
### Для начала использования
|
|
84
|
+
- #### Авто-установка
|
|
85
|
+
- выполните `pip install ttykit` в терминале
|
|
86
|
+
|
|
87
|
+
- #### Вручную
|
|
88
|
+
- #### Разрабатываемую версию
|
|
89
|
+
- скопируйте репозиторий
|
|
90
|
+
```bash
|
|
91
|
+
git clone https://github.com/He-STALIN/ttykit.git
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- перейдите в папку и выполни
|
|
95
|
+
```bash
|
|
96
|
+
pip install .
|
|
97
|
+
```
|
|
98
|
+
- #### Релизную версию
|
|
99
|
+
- Скачайте любой релиз из вкладки ["Releases"](https://github.com/He-STALIN/ttykit/releases)
|
|
100
|
+
|
|
101
|
+
- выполните в терминале
|
|
102
|
+
```bash
|
|
103
|
+
pip install <path>
|
|
104
|
+
```
|
|
105
|
+
Где `<path>` вам нужно вставить путь к скачанному файлу релиза
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
### Поддержите проект
|
|
109
|
+
- Если вы желаете, чтобы проект разрабатывался дальше, вы можете сделать [пожертвование](https://yoomoney.ru/to/4100118618732284/100).
|
|
110
|
+
- Счет: `4100 1186 1873 2284` (ЮМани)
|
|
111
|
+
- или
|
|
112
|
+
- Ищите ошибки в библиотеке и сообщайте о них в [`issues` на GitHub](https://github.com/He-STALIN/ttykit/issues).
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
### Примеры кода
|
|
116
|
+
- #### Status класс
|
|
117
|
+
```python
|
|
118
|
+
from ttykit import Status, TaskState
|
|
119
|
+
|
|
120
|
+
with Status("Какая-то задача", spinner="line") as status:
|
|
121
|
+
... # ваша нагрузка
|
|
122
|
+
status.set_state(TaskState.SUCCESS)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- #### Progress класс
|
|
126
|
+
```python
|
|
127
|
+
from ttykit import Progress
|
|
128
|
+
|
|
129
|
+
with Progress(100, "Некоторое описание", 40) as progress:
|
|
130
|
+
... # ваш код
|
|
131
|
+
progress.update(value)
|
|
132
|
+
... # и снова ваш код
|
|
133
|
+
progress.finish()
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
- **Для большего количества примеров и описания смотрите** [CODE USE](https://github.com/He-STALIN/ttykit/blob/main/docs/ru/CODE_USE.md)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
### Лицензия
|
|
140
|
+
- Это библиотека распространяется под лицензией MIT. [Смотреть лицензию](https://github.com/He-STALIN/ttykit/blob/main/LICENSE)
|
|
141
|
+
|
|
142
|
+
### Версии
|
|
143
|
+
- вам интересно узнать про версии? Вы можете посмотреть [CHANGELOG](https://github.com/He-STALIN/ttykit/blob/main/docs/ru/CHANGELOG.md)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
<div align="center">
|
|
148
|
+
|
|
149
|
+
*ttykit by He_STALIN. All rights reserved*
|
|
150
|
+
|
|
151
|
+
</div>
|
|
@@ -8,7 +8,7 @@ include = ["ttykit*"]
|
|
|
8
8
|
|
|
9
9
|
[project]
|
|
10
10
|
name = "ttykit"
|
|
11
|
-
version = "0.
|
|
11
|
+
version = "0.5.0"
|
|
12
12
|
description = "Helping made beatiful out in terminal"
|
|
13
13
|
requires-python = ">=3.13"
|
|
14
14
|
authors = [
|
|
@@ -16,12 +16,13 @@ authors = [
|
|
|
16
16
|
{email = "hene.stalin@gmail.com"}
|
|
17
17
|
]
|
|
18
18
|
license = {file = "LICENSE"}
|
|
19
|
-
readme = "README.md"
|
|
19
|
+
readme = "README.pypi.md"
|
|
20
20
|
keywords = ['tty', 'terminal', 'formatting']
|
|
21
|
-
dependencies = [
|
|
21
|
+
dependencies = []
|
|
22
22
|
|
|
23
23
|
[project.scripts]
|
|
24
24
|
ttykit-spinner = "ttykit.examples.spinner:main"
|
|
25
|
+
ttykit-progressbar = "ttykit.examples.progressbar:main"
|
|
25
26
|
|
|
26
27
|
[project.optional-dependencies]
|
|
27
28
|
test = ["pytest"]
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ttykit
|
|
3
|
+
=-=-=-=-=-=-=-=-=-=-=-
|
|
4
|
+
Helps produce attractive terminal output.
|
|
5
|
+
|
|
6
|
+
Author: He-STALIN
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Available imports:
|
|
10
|
+
├─ Classes:
|
|
11
|
+
│ + Progress
|
|
12
|
+
│ + Status
|
|
13
|
+
│ + Tree
|
|
14
|
+
│ + Console
|
|
15
|
+
├─ Submodules:
|
|
16
|
+
│ + data
|
|
17
|
+
│ - Input
|
|
18
|
+
│ + utils
|
|
19
|
+
├─ Methods:
|
|
20
|
+
│ + get_console
|
|
21
|
+
└─ In dev/un-ready:
|
|
22
|
+
- TUI (class)
|
|
23
|
+
- Input (submodule)
|
|
24
|
+
|
|
25
|
+
Documentation you can see here:
|
|
26
|
+
https://github.com/He-STALIN/ttykit/tree/main/docs
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
from .console.console import Console
|
|
30
|
+
from .console import input as Input
|
|
31
|
+
from .progress import Progress
|
|
32
|
+
from .console.TUI import TUI
|
|
33
|
+
from .status import Status
|
|
34
|
+
from .tree import Tree
|
|
35
|
+
from . import data, utils
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
__all__ = [
|
|
39
|
+
'Progress',
|
|
40
|
+
'Status',
|
|
41
|
+
'data',
|
|
42
|
+
'Console',
|
|
43
|
+
'Tree',
|
|
44
|
+
'TUI',
|
|
45
|
+
"Input",
|
|
46
|
+
'get_console',
|
|
47
|
+
'utils'
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
__name__ = 'ttykit'
|
|
51
|
+
__author__ = 'He-STALIN'
|
|
52
|
+
__version__ = '0.5.0'
|
|
53
|
+
__license__ = 'MIT'
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
console_inst: "Console" = None
|
|
57
|
+
|
|
58
|
+
def get_console() -> 'Console':
|
|
59
|
+
"""Return a instance of `Console`"""
|
|
60
|
+
global console_inst
|
|
61
|
+
if console_inst:
|
|
62
|
+
return console_inst
|
|
63
|
+
else:
|
|
64
|
+
console_inst = Console()
|
|
65
|
+
return console_inst
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
from ttykit import Input as kb
|
|
2
|
+
from warnings import warn
|
|
2
3
|
import os, sys
|
|
3
4
|
|
|
4
5
|
|
|
@@ -42,7 +43,7 @@ class TUI:
|
|
|
42
43
|
def __init__(self, title: str):
|
|
43
44
|
super().__init__()
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
warn("This class is not actually an interface and will be removed when a full-fledged TUI composer is created.", FutureWarning, stacklevel=2)
|
|
46
47
|
|
|
47
48
|
self.TITLE: str = title if title else "Text UI"
|
|
48
49
|
self.FOOTER: str = "For control use arrows Up/Down and Enter to select"
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import os
|
|
3
1
|
from typing import Optional, Literal, Mapping
|
|
4
|
-
from ttykit.segmentation import Segmentation
|
|
5
2
|
from getpass import getpass
|
|
3
|
+
import warnings
|
|
4
|
+
import sys
|
|
5
|
+
import os
|
|
6
6
|
|
|
7
|
-
from .const import ColorSystem, WINDOWS
|
|
7
|
+
from ttykit.data.const import ColorSystem, WINDOWS
|
|
8
|
+
from ttykit.segmentation import Segmentation
|
|
8
9
|
|
|
9
10
|
class Console:
|
|
10
11
|
"""
|
|
@@ -52,7 +53,7 @@ class Console:
|
|
|
52
53
|
size = os.get_terminal_size()
|
|
53
54
|
self.width = size.columns
|
|
54
55
|
except OSError:
|
|
55
|
-
|
|
56
|
+
warnings.warn('Error calculating width of the terminal. Use default value (80)', UserWarning)
|
|
56
57
|
self.width = 80
|
|
57
58
|
|
|
58
59
|
if self.height is None:
|
|
@@ -60,8 +61,8 @@ class Console:
|
|
|
60
61
|
size = os.get_terminal_size()
|
|
61
62
|
self.height = size.lines
|
|
62
63
|
except OSError:
|
|
63
|
-
|
|
64
|
-
self.height
|
|
64
|
+
warnings.warn('Error calculating height of the terminal. Use default value (24)', UserWarning)
|
|
65
|
+
self.height = 24
|
|
65
66
|
|
|
66
67
|
def _print_error(self, msg: str=None):
|
|
67
68
|
if msg is None:
|
|
@@ -69,6 +70,10 @@ class Console:
|
|
|
69
70
|
|
|
70
71
|
if self.stderr:
|
|
71
72
|
sys.stderr.write(msg)
|
|
73
|
+
else:
|
|
74
|
+
sys.stdout.write(msg)
|
|
75
|
+
|
|
76
|
+
sys.stdout.flush()
|
|
72
77
|
|
|
73
78
|
@property
|
|
74
79
|
def isTerminal(self) -> bool:
|
|
@@ -78,16 +83,16 @@ class Console:
|
|
|
78
83
|
Returns:
|
|
79
84
|
state (bool): return `True` if console is understanding escape sequences, otherwise `False`
|
|
80
85
|
"""
|
|
81
|
-
if self._force_terminal
|
|
86
|
+
if self._force_terminal not in [None, False]:
|
|
82
87
|
return True
|
|
83
88
|
|
|
84
89
|
if hasattr(sys.stdin, "__module__") and sys.stdin.__module__.startswith("idlelib"):
|
|
85
90
|
return False #? return False for idle which claims to be a tty but can't handle ANSI codes
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
if
|
|
92
|
+
ttyCompatible = self._environ.get('TTY_COMPATIBLE', '')
|
|
93
|
+
if ttyCompatible == '0': #? 0 = device is not tty compatible
|
|
89
94
|
return False
|
|
90
|
-
elif
|
|
95
|
+
elif ttyCompatible =='1': #? 1 = device is tty compatible
|
|
91
96
|
return True
|
|
92
97
|
|
|
93
98
|
if not sys.stdout.isatty():
|
|
@@ -132,14 +137,14 @@ class Console:
|
|
|
132
137
|
return ColorSystem.STANDARD
|
|
133
138
|
|
|
134
139
|
def bell(self):
|
|
135
|
-
sys.stdout.write("\
|
|
140
|
+
sys.stdout.write("\x07")
|
|
136
141
|
sys.stdout.flush()
|
|
137
142
|
|
|
138
143
|
def print(self,
|
|
139
144
|
*args,
|
|
140
145
|
sep: Optional[str] =" ",
|
|
141
146
|
end: Optional[str] ="\n",
|
|
142
|
-
justify:
|
|
147
|
+
justify: Literal["left", "center", "right"] = "left",
|
|
143
148
|
fillchar: str = " "
|
|
144
149
|
) -> None:
|
|
145
150
|
"""
|
|
@@ -159,7 +164,7 @@ class Console:
|
|
|
159
164
|
print("[blue] This is test string")
|
|
160
165
|
|
|
161
166
|
output:
|
|
162
|
-
|
|
167
|
+
This is test string
|
|
163
168
|
"""
|
|
164
169
|
if not self.isTerminal or self.no_color:
|
|
165
170
|
#? Just out, without colors or styles
|
|
@@ -207,8 +212,45 @@ class Console:
|
|
|
207
212
|
self.print(prompt, end='', justify=justify, fillchar=fillchar)
|
|
208
213
|
|
|
209
214
|
if password:
|
|
210
|
-
# TODO: realize text hidding
|
|
211
215
|
result = getpass(prompt='')
|
|
212
216
|
else:
|
|
213
217
|
result = input()
|
|
214
|
-
return result
|
|
218
|
+
return result
|
|
219
|
+
|
|
220
|
+
def set_cursor(self, width: int, height: int):
|
|
221
|
+
"""Set terminal cursor to coordinates"""
|
|
222
|
+
if not type(width) == int:
|
|
223
|
+
raise TypeError(f"Argument 'width' can be only 'int', not be {type(width)}")
|
|
224
|
+
if not type(height) == int:
|
|
225
|
+
raise TypeError(f"Argument 'height' can be only 'int', not be {type(height)}")
|
|
226
|
+
|
|
227
|
+
if width > self.width:
|
|
228
|
+
raise ValueError(f"Argument 'width' cannot exceed the terminal width, but '{width}' was received")
|
|
229
|
+
|
|
230
|
+
if height > self.height:
|
|
231
|
+
raise ValueError(f"Argument 'height' cannot exceed the terminal height, but '{height}' was received")
|
|
232
|
+
|
|
233
|
+
sys.stdout.write(f'\x1b[{height};{width}H')
|
|
234
|
+
sys.stdout.flush()
|
|
235
|
+
|
|
236
|
+
def set_alt_screen(self, enable: bool = True):
|
|
237
|
+
"""Set alternative screen of terminal"""
|
|
238
|
+
if self.isTerminal:
|
|
239
|
+
if enable:
|
|
240
|
+
sys.stdout.write('\x1b[?1049h') #? high - enable
|
|
241
|
+
sys.stdout.flush()
|
|
242
|
+
else:
|
|
243
|
+
sys.stdout.write('\x1b[?1049l') #? low - disable
|
|
244
|
+
sys.stdout.flush()
|
|
245
|
+
|
|
246
|
+
def set_window_title(self, title: str):
|
|
247
|
+
"""Sets the window title
|
|
248
|
+
|
|
249
|
+
Warning: some terminal (ex. `fish`) reset title before and after command executing"""
|
|
250
|
+
|
|
251
|
+
if not type(title) == str:
|
|
252
|
+
raise TypeError(f"Argument 'title' must be type of 'str'")
|
|
253
|
+
|
|
254
|
+
if self.isTerminal:
|
|
255
|
+
sys.stdout.write(f"\x1b]0;{title}\x07")
|
|
256
|
+
sys.stdout.flush()
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from typing import Callable as _Callable
|
|
2
|
+
import platform as _platform
|
|
3
|
+
from warnings import warn
|
|
4
|
+
|
|
5
|
+
from ._local import str_to_KeyEvent, KeyEvent_to_str
|
|
6
|
+
from ttykit.utils import InputWarning, SupportError, SupportWarning
|
|
7
|
+
from ttykit.data import KeyEvent as _KeyEvent
|
|
8
|
+
|
|
9
|
+
if _platform.system() == "Windows":
|
|
10
|
+
from ._windows import WindowsKeyboard as _Keyboard
|
|
11
|
+
elif _platform.system() == "Linux":
|
|
12
|
+
from ._unix import UnixKeyboard as _Keyboard
|
|
13
|
+
warn(
|
|
14
|
+
"Unix-related keyboard reader not fully made and may contain critical bugs",
|
|
15
|
+
InputWarning,
|
|
16
|
+
stacklevel=2
|
|
17
|
+
)
|
|
18
|
+
# elif _platform.system() == "Darwin":
|
|
19
|
+
else:
|
|
20
|
+
raise SupportError(f"Unsupported operating system: {_platform.system()}")
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
import IPython
|
|
24
|
+
warn("Submodule Input can don't work on IPython", SupportWarning)
|
|
25
|
+
except ImportError:
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
_kb = None
|
|
29
|
+
|
|
30
|
+
def add_hotkey(hotkey: str | _KeyEvent, callback: _Callable) -> None:
|
|
31
|
+
"""Adds a hotkey that executes when pressed
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
hotkey (str | KeyEvent):
|
|
35
|
+
Hotkey to which the call will be linked
|
|
36
|
+
callback (Callable):
|
|
37
|
+
The method that will be called
|
|
38
|
+
"""
|
|
39
|
+
_get_kb().add_hotkey(hotkey=hotkey, callback=callback)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def send(hotkey: str | _KeyEvent) -> None:
|
|
43
|
+
"""Send hotkey press and release"""
|
|
44
|
+
_get_kb().send(hotkey)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def release(hotkey: str | _KeyEvent) -> None:
|
|
48
|
+
"""Release pressed key"""
|
|
49
|
+
_get_kb().release(hotkey)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def press(hotkey: str | _KeyEvent) -> None:
|
|
53
|
+
"""presses and holds the key"""
|
|
54
|
+
_get_kb().press(hotkey)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def get_key() -> "_KeyEvent":
|
|
58
|
+
"""Returns the pressed key"""
|
|
59
|
+
return _get_kb().get_key()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def clear_all_hotkeys() -> None:
|
|
63
|
+
"""Reset all configured hotkeys"""
|
|
64
|
+
_get_kb().clear_all_hotkeys()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def clear_hotkey(hotkey: str | _KeyEvent) -> None:
|
|
68
|
+
"""Reset configured hotkey"""
|
|
69
|
+
_get_kb().clear_hotkey(hotkey)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _get_kb():
|
|
73
|
+
global _kb
|
|
74
|
+
if _kb is None:
|
|
75
|
+
_kb = _Keyboard()
|
|
76
|
+
return _kb
|
|
77
|
+
else:
|
|
78
|
+
return _kb
|
|
79
|
+
|
|
80
|
+
__all__ = [
|
|
81
|
+
'add_hotkey',
|
|
82
|
+
'send',
|
|
83
|
+
'release',
|
|
84
|
+
'press',
|
|
85
|
+
'get_key',
|
|
86
|
+
'clear_all_hotkeys',
|
|
87
|
+
'clear_hotkey',
|
|
88
|
+
'str_to_KeyEvent',
|
|
89
|
+
'KeyEvent_to_str'
|
|
90
|
+
]
|