grmenu 0.1.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.
- grmenu-0.1.0/GRmenu.py +160 -0
- grmenu-0.1.0/LICENSE +21 -0
- grmenu-0.1.0/PKG-INFO +42 -0
- grmenu-0.1.0/README.md +29 -0
- grmenu-0.1.0/pyproject.toml +30 -0
grmenu-0.1.0/GRmenu.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import termios
|
|
5
|
+
import tty
|
|
6
|
+
|
|
7
|
+
class GRmenu():
|
|
8
|
+
class GRprint:
|
|
9
|
+
real_print = print
|
|
10
|
+
|
|
11
|
+
@staticmethod
|
|
12
|
+
def p(text,end='\r\n',**extra):
|
|
13
|
+
GRmenu.GRprint.real_print(text, end=end,**extra)
|
|
14
|
+
|
|
15
|
+
def setFixPrint():
|
|
16
|
+
globals()['print'] = GRmenu.GRprint.p
|
|
17
|
+
|
|
18
|
+
def __init__(self,functions : list,title="",style=19):
|
|
19
|
+
self.D = sys.stdin.fileno()
|
|
20
|
+
self.DF = termios.tcgetattr(self.D)
|
|
21
|
+
tty.setraw(self.D)
|
|
22
|
+
self.functions = functions
|
|
23
|
+
self.style = style
|
|
24
|
+
self.GRprint.setFixPrint()
|
|
25
|
+
self.title = title
|
|
26
|
+
self.index = 0
|
|
27
|
+
self._clear_seq = "\x1b[H\x1b[2J\x1b[3J"
|
|
28
|
+
|
|
29
|
+
def _up(self):
|
|
30
|
+
self.index = (self.index - 1) % len(self.functions)
|
|
31
|
+
def _down(self):
|
|
32
|
+
self.index = (self.index + 1) % len(self.functions)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def STYLES():
|
|
37
|
+
return {
|
|
38
|
+
1:"#",2:"┌",3:"╔",4:"┏",5:"╒",6:"╓",7:"╭",8:"▛",
|
|
39
|
+
9:"▓",10:"▒",11:"░",12:"█",13:"*",14:"+",15:"=",
|
|
40
|
+
16:"~",17:"-",18:"◆",19:"●",20:"★"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def COLORS():
|
|
45
|
+
return {
|
|
46
|
+
"black": {1: "\x1b[30m", 2: "\x1b[90m"},
|
|
47
|
+
"red": {1: "\x1b[31m", 2: "\x1b[91m"},
|
|
48
|
+
"green": {1: "\x1b[32m", 2: "\x1b[92m"},
|
|
49
|
+
"yellow": {1: "\x1b[33m", 2: "\x1b[93m"},
|
|
50
|
+
"blue": {1: "\x1b[34m", 2: "\x1b[94m"},
|
|
51
|
+
"magenta":{1: "\x1b[35m", 2: "\x1b[95m"},
|
|
52
|
+
"cyan": {1: "\x1b[36m", 2: "\x1b[96m"},
|
|
53
|
+
"white": {1: "\x1b[37m", 2: "\x1b[97m"},
|
|
54
|
+
"reset": "\x1b[0m",
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def BORDERS():
|
|
59
|
+
return {
|
|
60
|
+
1: dict(h="=-", v="|", tl="#", tr="#", bl="#", br="#"),
|
|
61
|
+
2: dict(h="─", v="│", tl="┌", tr="┐", bl="└", br="┘"),
|
|
62
|
+
3: dict(h="═", v="║", tl="╔", tr="╗", bl="╚", br="╝"),
|
|
63
|
+
4: dict(h="━", v="┃", tl="┏", tr="┓", bl="┗", br="┛"),
|
|
64
|
+
5: dict(h="═", v="│", tl="╒", tr="╕", bl="╘", br="╛"),
|
|
65
|
+
6: dict(h="─", v="║", tl="╓", tr="╖", bl="╙", br="╜"),
|
|
66
|
+
7: dict(h="─", v="│", tl="╭", tr="╮", bl="╰", br="╯"),
|
|
67
|
+
8: dict(h="▀", v="▌", tl="▛", tr="▜", bl="▙", br="▟"),
|
|
68
|
+
19: dict(h="●○", v="●", tl="●", tr="●", bl="●", br="●"),
|
|
69
|
+
20: dict(h="★☆", v="★", tl="★", tr="★", bl="★", br="★"),
|
|
70
|
+
}
|
|
71
|
+
class SetStyle:
|
|
72
|
+
border = {"color": "cyan", "level": 1}
|
|
73
|
+
options = {"color": "white", "level": 1}
|
|
74
|
+
focus = {"color": "green", "level": 2}
|
|
75
|
+
|
|
76
|
+
@staticmethod
|
|
77
|
+
def Border(color, level=1):
|
|
78
|
+
GRmenu.SetStyle.border = {"color": color, "level": level}
|
|
79
|
+
|
|
80
|
+
@staticmethod
|
|
81
|
+
def Options(color, level=1):
|
|
82
|
+
GRmenu.SetStyle.options = {"color": color, "level": level}
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def Focus(color, level=2):
|
|
86
|
+
GRmenu.SetStyle.focus = {"color": color, "level": level}
|
|
87
|
+
|
|
88
|
+
@staticmethod
|
|
89
|
+
def _colorize(text, color_cfg):
|
|
90
|
+
if not color_cfg:
|
|
91
|
+
return text
|
|
92
|
+
colors = GRmenu.COLORS()
|
|
93
|
+
code = colors.get(color_cfg["color"], {}).get(color_cfg["level"], "")
|
|
94
|
+
if not code:
|
|
95
|
+
return text
|
|
96
|
+
return f"{code}{text}{colors['reset']}"
|
|
97
|
+
|
|
98
|
+
@staticmethod
|
|
99
|
+
def _hline(h, width):
|
|
100
|
+
return (h * (width // len(h) + 1))[:width]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def menu(self):
|
|
104
|
+
print("Press any key to start ...")
|
|
105
|
+
|
|
106
|
+
def draw(self,size_max=20):
|
|
107
|
+
self.menu()
|
|
108
|
+
while (key := os.read(self.D,3)) != b'q':
|
|
109
|
+
print(self._clear_seq, end="")
|
|
110
|
+
|
|
111
|
+
self._up() if key==b'\x1b[A' else None # up
|
|
112
|
+
self._down() if key==b'\x1b[B' else None # down
|
|
113
|
+
|
|
114
|
+
#print("right",end="\r\f") if key==b'\x1b[C' else None # right
|
|
115
|
+
#print("left",end="\r\f") if key==b'\x1b[D' else None # left
|
|
116
|
+
|
|
117
|
+
names = [getattr(f, "__name__", str(f)) for f in self.functions]
|
|
118
|
+
width = max([size_max] + [len(n) + 4 for n in names])
|
|
119
|
+
if self.title:
|
|
120
|
+
width = max(width, len(self.title) + 4)
|
|
121
|
+
bc, oc, fc = self.SetStyle.border, self.SetStyle.options, self.SetStyle.focus
|
|
122
|
+
box_border = self.BORDERS().get(self.style)
|
|
123
|
+
if box_border:
|
|
124
|
+
b = box_border
|
|
125
|
+
line = self._hline(b["h"], width - 2)
|
|
126
|
+
v = self._colorize(b["v"], bc)
|
|
127
|
+
print(self._colorize(b["tl"] + line + b["tr"], bc))
|
|
128
|
+
if self.title:
|
|
129
|
+
print(f"{v} {self.title.center(width - 4)} {v}")
|
|
130
|
+
print(self._colorize(b["v"] + line + b["v"], bc))
|
|
131
|
+
for name in names:
|
|
132
|
+
if self.index == names.index(name):
|
|
133
|
+
option = self._colorize(f">{name.ljust(width - 6)}", fc)
|
|
134
|
+
print(f"{v} {option} {v}")
|
|
135
|
+
else:
|
|
136
|
+
option = self._colorize(f"> {name.ljust(width - 6)}", oc)
|
|
137
|
+
print(f"{v} {option} {v}")
|
|
138
|
+
|
|
139
|
+
print(self._colorize(b["bl"] + line + b["br"], bc))
|
|
140
|
+
else:
|
|
141
|
+
symbol = self.STYLES().get(self.style, "#")
|
|
142
|
+
border = self._colorize(symbol, bc)
|
|
143
|
+
print(self._colorize(symbol * width, bc))
|
|
144
|
+
if self.title:
|
|
145
|
+
print(f"{border} {self.title.center(width - 4)} {border}")
|
|
146
|
+
print(self._colorize(symbol * width, bc))
|
|
147
|
+
for name in names:
|
|
148
|
+
if self.index == names.index(name):
|
|
149
|
+
print(f"{border} {self._colorize(name.ljust(width - 4), fc)} {border}")
|
|
150
|
+
else:
|
|
151
|
+
print(f"{border} {self._colorize(name.ljust(width - 4), oc)} {border}")
|
|
152
|
+
print(self._colorize(symbol * width, bc))
|
|
153
|
+
|
|
154
|
+
if key == b'\r':
|
|
155
|
+
termios.tcsetattr(self.D, termios.TCSAFLUSH, self.DF)
|
|
156
|
+
print(self._clear_seq)
|
|
157
|
+
self.functions[self.index]()
|
|
158
|
+
break
|
|
159
|
+
|
|
160
|
+
|
grmenu-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 grcode
|
|
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.
|
grmenu-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: grmenu
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Menu de navegacion por teclado para terminal en modo TTY crudo (flechas + Enter)
|
|
5
|
+
Author-email: grcode <gonzalezrosalesjoseeduardo@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Environment :: Console
|
|
9
|
+
Classifier: Operating System :: POSIX
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# grmenu
|
|
15
|
+
|
|
16
|
+
Libreria para crear menus de navegacion por teclado en terminal, en modo TTY
|
|
17
|
+
crudo (flechas arriba/abajo para moverse, Enter para elegir, `q` para salir).
|
|
18
|
+
|
|
19
|
+
Requiere Linux/macOS (usa los modulos `termios`/`tty`, no funciona en Windows).
|
|
20
|
+
|
|
21
|
+
## Instalacion
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install grmenu
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Uso
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from GRmenu import GRmenu
|
|
31
|
+
|
|
32
|
+
def opcion_uno():
|
|
33
|
+
print("elegiste uno")
|
|
34
|
+
|
|
35
|
+
def opcion_dos():
|
|
36
|
+
print("elegiste dos")
|
|
37
|
+
|
|
38
|
+
menu = GRmenu([opcion_uno, opcion_dos], title="Mi menu", style=19)
|
|
39
|
+
menu.SetStyle.Border("yellow")
|
|
40
|
+
menu.SetStyle.Options("green")
|
|
41
|
+
menu.draw()
|
|
42
|
+
```
|
grmenu-0.1.0/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# grmenu
|
|
2
|
+
|
|
3
|
+
Libreria para crear menus de navegacion por teclado en terminal, en modo TTY
|
|
4
|
+
crudo (flechas arriba/abajo para moverse, Enter para elegir, `q` para salir).
|
|
5
|
+
|
|
6
|
+
Requiere Linux/macOS (usa los modulos `termios`/`tty`, no funciona en Windows).
|
|
7
|
+
|
|
8
|
+
## Instalacion
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install grmenu
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Uso
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from GRmenu import GRmenu
|
|
18
|
+
|
|
19
|
+
def opcion_uno():
|
|
20
|
+
print("elegiste uno")
|
|
21
|
+
|
|
22
|
+
def opcion_dos():
|
|
23
|
+
print("elegiste dos")
|
|
24
|
+
|
|
25
|
+
menu = GRmenu([opcion_uno, opcion_dos], title="Mi menu", style=19)
|
|
26
|
+
menu.SetStyle.Border("yellow")
|
|
27
|
+
menu.SetStyle.Options("green")
|
|
28
|
+
menu.draw()
|
|
29
|
+
```
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "grmenu"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Menu de navegacion por teclado para terminal en modo TTY crudo (flechas + Enter)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "grcode", email = "gonzalezrosalesjoseeduardo@gmail.com" }
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Operating System :: POSIX",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[tool.hatch.build.targets.wheel]
|
|
22
|
+
include = ["GRmenu.py"]
|
|
23
|
+
|
|
24
|
+
[tool.hatch.build.targets.sdist]
|
|
25
|
+
include = [
|
|
26
|
+
"GRmenu.py",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"pyproject.toml",
|
|
30
|
+
]
|