pyetui 0.0.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.
pyetui-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyetui
3
+ Version: 0.0.1
4
+ Summary: Python easy tui
5
+ Requires-Python: >=3.10
@@ -0,0 +1,4 @@
1
+ __version__ = "1.0.0"
2
+
3
+ from .engine import menuTUI
4
+ from .utils import carousel_config
@@ -0,0 +1,47 @@
1
+ import os
2
+ from .utils.menuTUI import easy_menu_tui_dev
3
+ from rich.console import Console
4
+
5
+
6
+ class menuTUI:
7
+ def select(menu_type: str = "list",
8
+
9
+ title: str = "Add arguments, okay?",
10
+ choices: list | str = ["Ok", "No"],
11
+ choices_color: str = "white",
12
+ selected_choice_color: str = "white",
13
+ pointer: str = "> ",
14
+ spointer: str = "",
15
+ carousel_left_arrow: str = "< ",
16
+ carousel_right_arrow: str = " >",
17
+ qmark: str = "[#7700AB]?[/] ",
18
+ ):
19
+
20
+ if menu_type == "list":
21
+ menushowdisplay = easy_menu_tui_dev(title,
22
+ choices,
23
+ choices_color,
24
+ pointer,
25
+ spointer,
26
+ carousel_left_arrow,
27
+ carousel_right_arrow,
28
+ qmark,
29
+ selected_choice_color)
30
+ return menushowdisplay
31
+
32
+ if menu_type == "yesorno":
33
+ pass
34
+
35
+ class align:
36
+ def get_cols():
37
+ return os.get_terminal_size().columns
38
+
39
+ def get_rows():
40
+ return os.get_terminal_size().lines
41
+
42
+ def vertical(text):
43
+ lines = len(text.strip().splitlines())
44
+ return "\n" * ((get_rows() - lines) // 2) + text
45
+
46
+ def horizontal():
47
+ pass
@@ -0,0 +1,3 @@
1
+ def carousel(message="", max_limit=False, maintain_states=True, event="click-return"):
2
+ return f"message:{message} ;;; max_limit:{max_limit} ;;; maintain_states:{maintain_states} ;;; event:{event}"
3
+
@@ -0,0 +1,105 @@
1
+ import os
2
+ import time
3
+ import crossrun
4
+ from pynput import keyboard
5
+ from rich.panel import Panel
6
+ from rich.console import Console
7
+ from pynput.keyboard import Key
8
+
9
+ printf = Console().print
10
+
11
+ pressed_key = None
12
+
13
+ def on_press(key):
14
+ global pressed_key
15
+ pressed_key = key
16
+
17
+ listener = keyboard.Listener(on_press=on_press)
18
+ listener.start()
19
+
20
+ def list_display(choices, choices_color, selected_choice_color, title, pointer, secondary_pointer, panel, cs_left_pointer, cs_right_pointer, qmark):
21
+ """
22
+ print
23
+ """
24
+ global pressed_key
25
+
26
+ pointer_len = len(list(pointer))
27
+ void_pointer = " " * pointer_len
28
+
29
+
30
+ choice_local = 0
31
+ i = 0
32
+ first_draw = True
33
+
34
+ os.system("stty -echo")
35
+ first_draw = True
36
+ l = ""
37
+ printf(title if not panel else "")
38
+
39
+ cs_list = []
40
+ cs_index = 0
41
+
42
+
43
+ while True:
44
+ choices_display = "" if not panel else title + "\n"
45
+ if not first_draw:
46
+ for _ in range(len(choices) + (4 if panel else 1)):
47
+ print("\033[F\033[K", end="")
48
+ first_draw = False
49
+
50
+
51
+
52
+ for i, choice in enumerate(choices):
53
+ ptr = void_pointer
54
+ sptr = void_pointer
55
+ tsitc = False
56
+
57
+ if i == choice_local:
58
+ ptr = pointer
59
+ sptr = secondary_pointer
60
+ tsitc = True
61
+
62
+ colorvr = choices_color if not tsitc else selected_choice_color
63
+ choices_display += f"{ptr}[{colorvr}]{cs_left_pointer if isinstance(choice, list) else ''}{choice[cs_index] if isinstance(choice, list) else choice}{cs_right_pointer if isinstance(choice, list) else ''}[/]{sptr}\n"
64
+
65
+ printf(Panel(choices_display, expand=False) if panel else choices_display)
66
+
67
+ while True:
68
+ if pressed_key:
69
+ if pressed_key == Key.down:
70
+ if (len(choices) - 1) == choice_local:
71
+ continue
72
+
73
+ choice_local += 1
74
+
75
+ elif pressed_key == Key.up:
76
+ if 0 == choice_local:
77
+ continue
78
+
79
+
80
+ choice_local -= 1
81
+
82
+
83
+ if isinstance(choices[choice_local], list):
84
+ if pressed_key == Key.right:
85
+ if (len(choices[choice_local]) - 1) == cs_index:
86
+ cs_index = 0
87
+ continue
88
+
89
+ cs_index += 1
90
+
91
+ elif pressed_key == Key.left:
92
+ if cs_index == 0:
93
+ cs_index = (len(choices[choice_local]) - 1)
94
+ continue
95
+
96
+ cs_index -= 1
97
+
98
+ elif pressed_key == Key.enter:
99
+ os.system("stty echo")
100
+ choices[choice_local]
101
+
102
+ else:
103
+ continue
104
+ pressed_key = None
105
+ break
@@ -0,0 +1,202 @@
1
+ import os
2
+ import time
3
+
4
+ from rich.console import Console
5
+ from pynput import keyboard
6
+ from pynput.keyboard import Key
7
+
8
+ console = Console()
9
+
10
+ pressed_key = None
11
+
12
+
13
+ def on_press(key):
14
+ global pressed_key
15
+ pressed_key = key
16
+
17
+
18
+ listener = keyboard.Listener(on_press=on_press)
19
+ listener.start()
20
+
21
+
22
+ def easy_menu_tui_dev(
23
+ title,
24
+ choices,
25
+ choices_color,
26
+ pointer,
27
+ spointer,
28
+ carousel_left_arrow,
29
+ carousel_right_arrow,
30
+ qmark,
31
+ selected_choice_color
32
+ ):
33
+ global pressed_key
34
+
35
+ pressed_key = None
36
+
37
+ selection_index = 0
38
+ first_draw = True
39
+
40
+ void_pointer = " " * len(pointer)
41
+
42
+ # Índice individual para cada carrossel
43
+ carousel_indices = {}
44
+
45
+ for i, choice in enumerate(choices):
46
+ if isinstance(choice, list):
47
+ start_index = 1 if (
48
+ choice
49
+ and isinstance(choice[0], str)
50
+ and choice[0].startswith("message:")
51
+ ) else 0
52
+
53
+ carousel_indices[i] = start_index
54
+
55
+ os.system("stty -echo")
56
+
57
+ try:
58
+ while True:
59
+ choices_display = ""
60
+
61
+ if not first_draw:
62
+ total_lines = len(choices) + 1
63
+
64
+ for _ in range(total_lines):
65
+ print("\033[F\033[2K", end="")
66
+
67
+ first_draw = False
68
+
69
+ console.print(qmark + title)
70
+
71
+ for i, choice in enumerate(choices):
72
+ color = (
73
+ selected_choice_color
74
+ if i == selection_index
75
+ else choices_color
76
+ )
77
+
78
+ pointer_condition = (
79
+ pointer if i == selection_index else void_pointer
80
+ )
81
+
82
+ secondary_pointer = (
83
+ spointer if i == selection_index else ""
84
+ )
85
+
86
+ if isinstance(choice, list):
87
+ current = choice.copy()
88
+
89
+ message = ""
90
+
91
+ if (
92
+ current
93
+ and isinstance(current[0], str)
94
+ and current[0].startswith("message:")
95
+ ):
96
+ message = (
97
+ current.pop(0)
98
+ .removeprefix("message:").lstrip()
99
+ )
100
+
101
+ index = carousel_indices[i] % len(current)
102
+ value = current[index]
103
+
104
+ choices_display += (
105
+ f"{pointer_condition}"
106
+ f"[{color}]{message}[/]"
107
+ f"{carousel_left_arrow}"
108
+ f"[{color}]{value}[/]"
109
+ f"{carousel_right_arrow}"
110
+ f"{secondary_pointer}\n"
111
+ )
112
+
113
+ else:
114
+ choices_display += (
115
+ f"{pointer_condition}"
116
+ f"[{color}]{choice}[/]"
117
+ f"{secondary_pointer}\n"
118
+ )
119
+ console.print(choices_display, end="")
120
+
121
+ while True:
122
+ time.sleep(0.02)
123
+
124
+ if pressed_key is None:
125
+ continue
126
+
127
+ key = pressed_key
128
+ pressed_key = None
129
+
130
+ if key == Key.down:
131
+ selection_index = min(
132
+ selection_index + 1,
133
+ len(choices) - 1
134
+ )
135
+ break
136
+
137
+ elif key == Key.up:
138
+ selection_index = max(
139
+ selection_index - 1,
140
+ 0
141
+ )
142
+ break
143
+
144
+ elif key == Key.right:
145
+ selected = choices[selection_index]
146
+
147
+ if isinstance(selected, list):
148
+ current = selected.copy()
149
+
150
+ if (
151
+ current
152
+ and isinstance(current[0], str)
153
+ and current[0].startswith("message:")
154
+ ):
155
+ current.pop(0)
156
+
157
+ carousel_indices[selection_index] = (
158
+ carousel_indices[selection_index] + 1
159
+ ) % len(current)
160
+
161
+ break
162
+
163
+ elif key == Key.left:
164
+ selected = choices[selection_index]
165
+
166
+ if isinstance(selected, list):
167
+ current = selected.copy()
168
+
169
+ if (
170
+ current
171
+ and isinstance(current[0], str)
172
+ and current[0].startswith("message:")
173
+ ):
174
+ current.pop(0)
175
+
176
+ carousel_indices[selection_index] = (
177
+ carousel_indices[selection_index] - 1
178
+ ) % len(current)
179
+
180
+ break
181
+
182
+ elif key == Key.enter:
183
+ selected = choices[selection_index]
184
+
185
+ if isinstance(selected, list):
186
+ current = selected.copy()
187
+
188
+ if (
189
+ current
190
+ and isinstance(current[0], str)
191
+ and current[0].startswith("message:")
192
+ ):
193
+ current.pop(0)
194
+
195
+ return current[
196
+ carousel_indices[selection_index]
197
+ ]
198
+
199
+ return selected
200
+
201
+ finally:
202
+ os.system("stty echo")
@@ -0,0 +1,5 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyetui
3
+ Version: 0.0.1
4
+ Summary: Python easy tui
5
+ Requires-Python: >=3.10
@@ -0,0 +1,11 @@
1
+ pyproject.toml
2
+ pyetui/__init__.py
3
+ pyetui/engine.py
4
+ pyetui.egg-info/PKG-INFO
5
+ pyetui.egg-info/SOURCES.txt
6
+ pyetui.egg-info/dependency_links.txt
7
+ pyetui.egg-info/top_level.txt
8
+ pyetui/utils/carousel_config.py
9
+ pyetui/utils/list_menu.py
10
+ pyetui/utils/menuTUI.py
11
+ tests/test.py
@@ -0,0 +1 @@
1
+ pyetui
@@ -0,0 +1,5 @@
1
+ [project]
2
+ name = "pyetui"
3
+ version = "0.0.1"
4
+ description = "Python easy tui"
5
+ requires-python = ">=3.10"
pyetui-0.0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,20 @@
1
+ import pyetui
2
+ from pyetui.utils import carousel_config
3
+
4
+ print("texto print teste")
5
+ print()
6
+ choice = pyetui.menuTUI.select(
7
+ title="configs",
8
+ choices=["python", "ruby", ["message: oiiiiiiiii", "teste1", "teste2", "teste3"], "outras", ["message: langs c: ", "c", "c++", "c#"], ["c", "hh"]],
9
+ choices_color="#989898",
10
+ selected_choice_color="#FFFFFF",
11
+ spointer=" <"
12
+
13
+ )
14
+
15
+ print(choice)
16
+
17
+ if choice == 0:
18
+ print("py")
19
+
20
+ input()