ttykit 0.3.0b4__tar.gz → 0.3.5__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.3.0b4/src/ttykit.egg-info → ttykit-0.3.5}/PKG-INFO +2 -1
- {ttykit-0.3.0b4 → ttykit-0.3.5}/pyproject.toml +3 -3
- {ttykit-0.3.0b4 → ttykit-0.3.5}/src/ttykit/__init__.py +3 -1
- ttykit-0.3.5/src/ttykit/console/TUI.py +148 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5/src/ttykit.egg-info}/PKG-INFO +2 -1
- {ttykit-0.3.0b4 → ttykit-0.3.5}/src/ttykit.egg-info/SOURCES.txt +1 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/src/ttykit.egg-info/requires.txt +1 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/LICENSE +0 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/README.md +0 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/setup.cfg +0 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/src/ttykit/_state.py +0 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/src/ttykit/console/console.py +0 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/src/ttykit/console/const.py +0 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/src/ttykit/progress.py +0 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/src/ttykit/spinner.py +0 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/src/ttykit/status.py +0 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/src/ttykit.egg-info/dependency_links.txt +0 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/src/ttykit.egg-info/entry_points.txt +0 -0
- {ttykit-0.3.0b4 → ttykit-0.3.5}/src/ttykit.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ttykit
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5
|
|
4
4
|
Summary: Helping made beatiful out in terminal
|
|
5
5
|
Author: He-STALIN
|
|
6
6
|
Author-email: hene.stalin@gmail.com
|
|
@@ -32,6 +32,7 @@ Keywords: tty,terminal,formatting
|
|
|
32
32
|
Requires-Python: >=3.13
|
|
33
33
|
Description-Content-Type: text/markdown
|
|
34
34
|
License-File: LICENSE
|
|
35
|
+
Requires-Dist: keyboard
|
|
35
36
|
Provides-Extra: test
|
|
36
37
|
Requires-Dist: pytest; extra == "test"
|
|
37
38
|
Dynamic: license-file
|
|
@@ -8,17 +8,17 @@ include = ["ttykit*"]
|
|
|
8
8
|
|
|
9
9
|
[project]
|
|
10
10
|
name = "ttykit"
|
|
11
|
-
version = "0.3.
|
|
11
|
+
version = "0.3.5"
|
|
12
12
|
description = "Helping made beatiful out in terminal"
|
|
13
13
|
requires-python = ">=3.13"
|
|
14
14
|
authors = [
|
|
15
|
-
{
|
|
15
|
+
{name = "He-STALIN"},
|
|
16
16
|
{email = "hene.stalin@gmail.com"}
|
|
17
17
|
]
|
|
18
18
|
license = {file = "LICENSE"}
|
|
19
19
|
readme = "README.md"
|
|
20
20
|
keywords = ['tty', 'terminal', 'formatting']
|
|
21
|
-
dependencies = []
|
|
21
|
+
dependencies = ["keyboard"]
|
|
22
22
|
|
|
23
23
|
[project.scripts]
|
|
24
24
|
ttykit-spinner = "ttykit.spinner:main"
|
|
@@ -4,6 +4,7 @@ from .progress import Progress
|
|
|
4
4
|
from .status import Status
|
|
5
5
|
from ._state import TaskState, Colors, Styles, RESET
|
|
6
6
|
from .console.console import Console
|
|
7
|
+
from .console.TUI import TUI
|
|
7
8
|
import traceback
|
|
8
9
|
import sys
|
|
9
10
|
|
|
@@ -18,6 +19,7 @@ __all__ = [
|
|
|
18
19
|
'Status',
|
|
19
20
|
'TaskState',
|
|
20
21
|
'Console',
|
|
22
|
+
'TUI',
|
|
21
23
|
'get_console',
|
|
22
24
|
'set_custom_hook'
|
|
23
25
|
]
|
|
@@ -63,5 +65,5 @@ def set_custom_hook(Traceback: bool= False) -> None:
|
|
|
63
65
|
|
|
64
66
|
__name__ = 'ttykit'
|
|
65
67
|
__author__ = 'He-STALIN'
|
|
66
|
-
__version__ = '0.3.
|
|
68
|
+
__version__ = '0.3.5'
|
|
67
69
|
__license__ = 'MIT'
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import keyboard as kb
|
|
2
|
+
import os, sys
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TUI:
|
|
6
|
+
"""
|
|
7
|
+
Create TUI (Text User Interface) in terminal with user menus
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
title (str): title of the `TUI`
|
|
11
|
+
|
|
12
|
+
### Methods:
|
|
13
|
+
`addMenu(name, callback)`: add menu to UI render.
|
|
14
|
+
`Run()`: exec and start render the UI.
|
|
15
|
+
`UpdateUI()`: forced update UI Layer.
|
|
16
|
+
|
|
17
|
+
### Examples
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from ttykit import TUI
|
|
21
|
+
|
|
22
|
+
ui = TUI("this example UI!")
|
|
23
|
+
|
|
24
|
+
def someAction():
|
|
25
|
+
# do something
|
|
26
|
+
|
|
27
|
+
ui.addMenu("Us menu", someAction) # adding menu in UI
|
|
28
|
+
|
|
29
|
+
ui.Run() # and start render UI
|
|
30
|
+
```
|
|
31
|
+
Out in Terminal
|
|
32
|
+
```
|
|
33
|
+
===[ this example UI! ]===
|
|
34
|
+
|
|
35
|
+
> Us menu
|
|
36
|
+
|
|
37
|
+
> Exit
|
|
38
|
+
|
|
39
|
+
For control use arrows Up/Down and Enter to select
|
|
40
|
+
```
|
|
41
|
+
"""
|
|
42
|
+
def __init__(self, title: str):
|
|
43
|
+
super().__init__()
|
|
44
|
+
self.TITLE: str = title if title else "Text UI"
|
|
45
|
+
self.FOOTER: str = "For control use arrows Up/Down and Enter to select"
|
|
46
|
+
self.DEFAULT_SPACE = " "
|
|
47
|
+
self._requestClosing: bool = False
|
|
48
|
+
self.action: int = 1
|
|
49
|
+
self._max_menus: int = 0
|
|
50
|
+
self._menus: list = []
|
|
51
|
+
kb.add_hotkey("Up", self.UpMenu)
|
|
52
|
+
kb.add_hotkey("Down", self.DownMenu)
|
|
53
|
+
kb.add_hotkey("enter", self._selectAction)
|
|
54
|
+
|
|
55
|
+
def _clearTerminal(self):
|
|
56
|
+
os.system('cls' if os.name == 'nt' else 'clear')
|
|
57
|
+
|
|
58
|
+
def _selectAction(self):
|
|
59
|
+
if self.action == self._max_menus:
|
|
60
|
+
self._requestClosing = True
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
menu = self._menus[self.action - 1]
|
|
64
|
+
menu["callback"]()
|
|
65
|
+
|
|
66
|
+
def _UpMenu(self):
|
|
67
|
+
self.action -= 1
|
|
68
|
+
|
|
69
|
+
if self.action < 1:
|
|
70
|
+
self.action = self._max_menus
|
|
71
|
+
|
|
72
|
+
self.UpdateUI()
|
|
73
|
+
|
|
74
|
+
def _DownMenu(self):
|
|
75
|
+
self.action += 1
|
|
76
|
+
|
|
77
|
+
if self.action > self._max_menus:
|
|
78
|
+
self.action = 1
|
|
79
|
+
|
|
80
|
+
self.UpdateUI()
|
|
81
|
+
|
|
82
|
+
def UpdateUI(self):
|
|
83
|
+
"""Update UI Layer in Terminal"""
|
|
84
|
+
TUI = ""
|
|
85
|
+
TUI += f"===[ {self.TITLE} ]==="
|
|
86
|
+
TUI += "\n\n"
|
|
87
|
+
|
|
88
|
+
_current_menu = 1
|
|
89
|
+
for menu in self._menus:
|
|
90
|
+
if self.action == _current_menu:
|
|
91
|
+
TUI += f"{self.DEFAULT_SPACE}\033[34m> {menu["name"]}\033[0m\n"
|
|
92
|
+
else:
|
|
93
|
+
TUI += f"{self.DEFAULT_SPACE}> {menu["name"]}\033[0m\n"
|
|
94
|
+
|
|
95
|
+
TUI += "\n"
|
|
96
|
+
_current_menu += 1
|
|
97
|
+
|
|
98
|
+
if len(self._menus) == self._max_menus:
|
|
99
|
+
self._max_menus += 1 #? add Exit menu in UI
|
|
100
|
+
|
|
101
|
+
if self.action == self._max_menus: #? exit menu always is last
|
|
102
|
+
TUI += f"{self.DEFAULT_SPACE}\033[31m> Exit\033[0m\n"
|
|
103
|
+
else:
|
|
104
|
+
TUI += f"{self.DEFAULT_SPACE}> Exit\033[0m\n"
|
|
105
|
+
|
|
106
|
+
TUI += "\n" + self.FOOTER + "\n"
|
|
107
|
+
|
|
108
|
+
sys.stdout.write("\033[H") #? set cursor to pos (0, 0)
|
|
109
|
+
sys.stdout.write(TUI)
|
|
110
|
+
sys.stdout.flush()
|
|
111
|
+
|
|
112
|
+
def addMenu(self, name: str, callback):
|
|
113
|
+
"""
|
|
114
|
+
Adding menu to UI.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
name (str): name of the menu
|
|
118
|
+
callback: what need to call, when menu selected
|
|
119
|
+
"""
|
|
120
|
+
try:
|
|
121
|
+
self._menus.append({
|
|
122
|
+
"name": name,
|
|
123
|
+
"callback": callback
|
|
124
|
+
})
|
|
125
|
+
self._max_menus += 1
|
|
126
|
+
except Exception as e:
|
|
127
|
+
raise Exception(e)
|
|
128
|
+
|
|
129
|
+
def Run(self):
|
|
130
|
+
if len(self._menus) < 1:
|
|
131
|
+
raise ValueError("UI can't has been created without menus")
|
|
132
|
+
|
|
133
|
+
try:
|
|
134
|
+
self._clearTerminal()
|
|
135
|
+
self.UpdateUI()
|
|
136
|
+
while True:
|
|
137
|
+
if self._requestClosing:
|
|
138
|
+
sys.exit()
|
|
139
|
+
break
|
|
140
|
+
else:
|
|
141
|
+
pass
|
|
142
|
+
|
|
143
|
+
except KeyboardInterrupt:
|
|
144
|
+
sys.stdout.write("[!] Exited by user\n")
|
|
145
|
+
sys.stdout.flush()
|
|
146
|
+
|
|
147
|
+
except Exception as e:
|
|
148
|
+
raise Exception(e)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ttykit
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5
|
|
4
4
|
Summary: Helping made beatiful out in terminal
|
|
5
5
|
Author: He-STALIN
|
|
6
6
|
Author-email: hene.stalin@gmail.com
|
|
@@ -32,6 +32,7 @@ Keywords: tty,terminal,formatting
|
|
|
32
32
|
Requires-Python: >=3.13
|
|
33
33
|
Description-Content-Type: text/markdown
|
|
34
34
|
License-File: LICENSE
|
|
35
|
+
Requires-Dist: keyboard
|
|
35
36
|
Provides-Extra: test
|
|
36
37
|
Requires-Dist: pytest; extra == "test"
|
|
37
38
|
Dynamic: license-file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|