python-tty 0.1.0__py3-none-any.whl
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.
- python_tty/__init__.py +15 -0
- python_tty/commands/__init__.py +24 -0
- python_tty/commands/core.py +119 -0
- python_tty/commands/decorators.py +58 -0
- python_tty/commands/examples/__init__.py +8 -0
- python_tty/commands/examples/root_commands.py +33 -0
- python_tty/commands/examples/sub_commands.py +11 -0
- python_tty/commands/general.py +107 -0
- python_tty/commands/mixins.py +52 -0
- python_tty/commands/registry.py +185 -0
- python_tty/config/__init__.py +9 -0
- python_tty/config/config.py +35 -0
- python_tty/console_factory.py +100 -0
- python_tty/consoles/__init__.py +16 -0
- python_tty/consoles/core.py +140 -0
- python_tty/consoles/decorators.py +42 -0
- python_tty/consoles/examples/__init__.py +8 -0
- python_tty/consoles/examples/root_console.py +34 -0
- python_tty/consoles/examples/sub_console.py +34 -0
- python_tty/consoles/loader.py +14 -0
- python_tty/consoles/manager.py +146 -0
- python_tty/consoles/registry.py +102 -0
- python_tty/exceptions/__init__.py +7 -0
- python_tty/exceptions/console_exception.py +12 -0
- python_tty/executor/__init__.py +10 -0
- python_tty/executor/executor.py +335 -0
- python_tty/executor/models.py +38 -0
- python_tty/frontends/__init__.py +0 -0
- python_tty/meta/__init__.py +0 -0
- python_tty/ui/__init__.py +13 -0
- python_tty/ui/events.py +55 -0
- python_tty/ui/output.py +102 -0
- python_tty/utils/__init__.py +13 -0
- python_tty/utils/table.py +126 -0
- python_tty/utils/tokenize.py +45 -0
- python_tty/utils/ui_logger.py +17 -0
- python_tty-0.1.0.dist-info/METADATA +66 -0
- python_tty-0.1.0.dist-info/RECORD +40 -0
- python_tty-0.1.0.dist-info/WHEEL +5 -0
- python_tty-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import shlex
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def tokenize_cmd(cmd: str):
|
|
5
|
+
cmd = cmd.strip()
|
|
6
|
+
if cmd == "":
|
|
7
|
+
return []
|
|
8
|
+
try:
|
|
9
|
+
return shlex.split(cmd, posix=True)
|
|
10
|
+
except ValueError as exc:
|
|
11
|
+
raise ValueError("Invalid command arguments") from exc
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_command_token(cmd: str):
|
|
15
|
+
tokens = tokenize_cmd(cmd)
|
|
16
|
+
return tokens[0] if tokens else ""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_func_param_strs(cmd: str, param_count: int):
|
|
20
|
+
if param_count <= 0:
|
|
21
|
+
return None
|
|
22
|
+
cmd = cmd.strip()
|
|
23
|
+
if cmd == "":
|
|
24
|
+
return []
|
|
25
|
+
if param_count == 1:
|
|
26
|
+
tokens = tokenize_cmd(cmd)
|
|
27
|
+
if len(tokens) == 1:
|
|
28
|
+
return tokens
|
|
29
|
+
return [cmd]
|
|
30
|
+
return tokenize_cmd(cmd)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def split_cmd(cmd: str):
|
|
34
|
+
stripped = cmd.lstrip()
|
|
35
|
+
if stripped == "":
|
|
36
|
+
return "", "", []
|
|
37
|
+
tokens = tokenize_cmd(stripped)
|
|
38
|
+
if not tokens:
|
|
39
|
+
return "", "", []
|
|
40
|
+
token = tokens[0]
|
|
41
|
+
if stripped.startswith(token):
|
|
42
|
+
remainder = stripped[len(token):].lstrip()
|
|
43
|
+
else:
|
|
44
|
+
remainder = " ".join(tokens[1:])
|
|
45
|
+
return token, remainder, tokens
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
from python_tty.ui.events import UIEventLevel
|
|
4
|
+
from python_tty.ui.output import proxy_print
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ConsoleHandler(logging.Handler):
|
|
8
|
+
def __init__(self):
|
|
9
|
+
super().__init__()
|
|
10
|
+
|
|
11
|
+
def emit(self, record):
|
|
12
|
+
try:
|
|
13
|
+
log = self.format(record)
|
|
14
|
+
proxy_print(log, UIEventLevel.DEBUG)
|
|
15
|
+
except Exception:
|
|
16
|
+
self.handleError(record)
|
|
17
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-tty
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A multi-console TTY framework for complex CLI/TTY apps
|
|
5
|
+
Home-page: https://github.com/ROOKIEMIE/python-tty
|
|
6
|
+
Author: ROOKIEMIE
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: prompt_toolkit>=3.0.32
|
|
10
|
+
Requires-Dist: tqdm
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: description
|
|
13
|
+
Dynamic: description-content-type
|
|
14
|
+
Dynamic: home-page
|
|
15
|
+
Dynamic: requires-dist
|
|
16
|
+
Dynamic: requires-python
|
|
17
|
+
Dynamic: summary
|
|
18
|
+
|
|
19
|
+
# Command Line Framework (V2: Web/RPC-ready)
|
|
20
|
+
|
|
21
|
+
[中文](README_zh.md)
|
|
22
|
+
|
|
23
|
+
V2 extends the TTY core toward Web + RPC, while keeping the current codebase focused on the TTY runtime. At the moment, Web/RPC is planned but not yet implemented.
|
|
24
|
+
|
|
25
|
+
## Quick Start (TTY Core)
|
|
26
|
+
|
|
27
|
+
1) Define your consoles and commands (see examples in `src/consoles/examples` and `src/commands/examples`).
|
|
28
|
+
2) Ensure console modules are imported so decorators can register them:
|
|
29
|
+
- Update `DEFAULT_CONSOLE_MODULES` in `src/consoles/loader.py`, or
|
|
30
|
+
- Call `load_consoles([...])` manually.
|
|
31
|
+
3) Start the factory:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from src.console_factory import ConsoleFactory
|
|
35
|
+
|
|
36
|
+
factory = ConsoleFactory(service=my_business_core)
|
|
37
|
+
factory.start()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The `service` instance is available in all consoles via `console.service`, and in commands via `self.console.service`. If `service` does not inherit `UIEventSpeaker`, a warning is emitted at startup.
|
|
41
|
+
|
|
42
|
+
## Current Capabilities (TTY Core)
|
|
43
|
+
|
|
44
|
+
Console layer:
|
|
45
|
+
- `src/consoles/core.py`: `BaseConsole`, `MainConsole`, `SubConsole`
|
|
46
|
+
- `src/consoles/manager.py` and `src/consoles/registry.py` for lifecycle and registration
|
|
47
|
+
|
|
48
|
+
Commands layer:
|
|
49
|
+
- `src/commands/core.py`: `BaseCommands`, `CommandValidator`
|
|
50
|
+
- `src/commands/registry.py`: `CommandRegistry`, `ArgSpec`
|
|
51
|
+
- `src/commands/general.py`: `GeneralValidator`, `GeneralCompleter`
|
|
52
|
+
- `src/commands/mixins.py`: `CommandMixin` and built-in mixins
|
|
53
|
+
|
|
54
|
+
UI and utilities:
|
|
55
|
+
- `src/core/events.py`: `UIEvent`, `UIEventLevel`, `UIEventSpeaker`
|
|
56
|
+
- `src/ui/output.py`: `proxy_print`
|
|
57
|
+
- `src/utils/`: `tokenize.py`, `table.py`, `ui_logger.py`
|
|
58
|
+
|
|
59
|
+
## Roadmap (V2)
|
|
60
|
+
|
|
61
|
+
Planned milestones for Web + RPC:
|
|
62
|
+
- M1: Meta Descriptor v1 + Exporter
|
|
63
|
+
- M2: RPC proto v1 + local (de)serialization
|
|
64
|
+
- M3: Meta Web Server (HTTP + WS)
|
|
65
|
+
- M4: RPC Server (mTLS + allowlist + audit)
|
|
66
|
+
- M5: Unified execution system (CommandExecutor)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
python_tty/__init__.py,sha256=VZvoBsZTUvvolO2r3hwsC2r-BDTxjpy6zZjykO0_ZT4,376
|
|
2
|
+
python_tty/console_factory.py,sha256=yRWXsh8mNGyAxUUXe3el3ENKqL4fuAfUqZYBtScCii4,3666
|
|
3
|
+
python_tty/commands/__init__.py,sha256=n3Thx4nzfnwFzEJ6JtrpX0_WuC1bntjtlH3-_ZSPPx8,455
|
|
4
|
+
python_tty/commands/core.py,sha256=3TNfSGfMa8VxO_6Eoj7qMGJgnIdUGejHK2_UDReaeHo,4892
|
|
5
|
+
python_tty/commands/decorators.py,sha256=MTCQrFlTK8cAHrgGjtjHETVmdnYI4-51G6CpcGP74S0,2656
|
|
6
|
+
python_tty/commands/general.py,sha256=2uu848GJzdMpYv0bOAZwG7zczxeczzk0Ppdt413rjG0,3555
|
|
7
|
+
python_tty/commands/mixins.py,sha256=zI47zAFmZ2uvuzohpq4wabXiHb45PbbXxmYkAVaM5Lw,1761
|
|
8
|
+
python_tty/commands/registry.py,sha256=NQg87PHDSH8Pk8Zg9oUayi76O0LAJ-8EDAyrCdypH-0,7041
|
|
9
|
+
python_tty/commands/examples/__init__.py,sha256=hToJIEZp-EK5atELlxola1U6pd-w21yhIqxD1MXo170,190
|
|
10
|
+
python_tty/commands/examples/root_commands.py,sha256=L7cVS5I5ZrIrdSPS1Z1EIlOLN6WRDT925LSBR7uLi4M,1200
|
|
11
|
+
python_tty/commands/examples/sub_commands.py,sha256=7Mfn48u8nKRTkY1bc3Fj4qYU9e_7aU8dB829AOQmDmc,447
|
|
12
|
+
python_tty/config/__init__.py,sha256=5NlOOKUL0BqqO0zFPyN8N0MUDyfobEfjF2UM_FLkgkY,213
|
|
13
|
+
python_tty/config/config.py,sha256=Seis2foQv6f1AEVQZM0IQGRYJBs2Dixm3G0hYlXIa0E,910
|
|
14
|
+
python_tty/consoles/__init__.py,sha256=A_MC6Ot1EuQvjeSM75y5lE4WSbDph_t1JQYX8nuhmSU,403
|
|
15
|
+
python_tty/consoles/core.py,sha256=ZWJub29TrlZB6oRXNXBRMGUvnNqvuUn_QT_tVa2lUaQ,5340
|
|
16
|
+
python_tty/consoles/decorators.py,sha256=1RvZBpNXmvAF0J81duLc2uXsd9fX8VUrM5ZAPQjZqwQ,1554
|
|
17
|
+
python_tty/consoles/loader.py,sha256=FAlRwewsiJb5qkqgmPDKEszJ59X4nG85QHbhfc-knBQ,371
|
|
18
|
+
python_tty/consoles/manager.py,sha256=Z-0WepObqIL-Alt_ZmEIl9Kv-rMYy_xWSU359g2tYfw,4928
|
|
19
|
+
python_tty/consoles/registry.py,sha256=IlwP-uhK8EnN-M4lEqdr8wggn9BJdraDGcq8u_BvIOw,3891
|
|
20
|
+
python_tty/consoles/examples/__init__.py,sha256=8f_zr6JPVx1CCR9SEqqUVVOh689t6pZ0XoAigEnftDQ,190
|
|
21
|
+
python_tty/consoles/examples/root_console.py,sha256=lg_p1KIYhF1z3WfGaoWsXelm46KD8HRHq_47F8Ol3yQ,834
|
|
22
|
+
python_tty/consoles/examples/sub_console.py,sha256=K-IyIy1UL4kj6QKCU-L-4CUSzPca-Flw-ePaKPmNa6Q,885
|
|
23
|
+
python_tty/exceptions/__init__.py,sha256=58tyDjS4S_jL4axvdmnryLoE9Sr73o5U6jehZvivbd8,161
|
|
24
|
+
python_tty/exceptions/console_exception.py,sha256=5xwfYsHvqYmFVnwbGq3eDGk9FZyE6eV9l6YobTqaa-w,231
|
|
25
|
+
python_tty/executor/__init__.py,sha256=k4Jv7n72IQN9BLmvi6ENbKhq405E5x8ongnVJXUFUhw,219
|
|
26
|
+
python_tty/executor/executor.py,sha256=pnIODl4nI_foU6mgt6KdDiFLpGvVvAOUY6yWrATii7M,13561
|
|
27
|
+
python_tty/executor/models.py,sha256=FJDxV58DR2pK3g5-kA0d-SLcBV14nn6Fm34MhmkKx30,997
|
|
28
|
+
python_tty/frontends/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
|
+
python_tty/meta/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
30
|
+
python_tty/ui/__init__.py,sha256=wBSHvOMA8cZJQJk4D8UjvqHB3ujvBte0E064IUABbbc,327
|
|
31
|
+
python_tty/ui/events.py,sha256=qgyhDjkdU-K6j7_LDz9G33OZZxkHWOVxulq-oMzUBuU,1356
|
|
32
|
+
python_tty/ui/output.py,sha256=3_linB6hpDfQHbuff6bm9HcdgCB21RUrkDI7iHvL5x8,2690
|
|
33
|
+
python_tty/utils/__init__.py,sha256=8ky8A4s6NbxaEokdnUxhCxgIXjq5nFCeyOApjg0RfvI,338
|
|
34
|
+
python_tty/utils/table.py,sha256=rAzxm-XTKbvKsn1Qoe_rXVjU6_5nQpJzSkgYZIRQBK8,4310
|
|
35
|
+
python_tty/utils/tokenize.py,sha256=TnZd1o6LmvqbMWON_RTVk4q664TviIQTFVkNX4CTUBs,1055
|
|
36
|
+
python_tty/utils/ui_logger.py,sha256=dCqflrliX2T6GdTFonUwEiHYHHF-wlj1QkqpVsFvxio,393
|
|
37
|
+
python_tty-0.1.0.dist-info/METADATA,sha256=6gjvKuhYCMWeiyoEIy7gS2Z6jSrPK1VI8grMmqXiP6E,2293
|
|
38
|
+
python_tty-0.1.0.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
39
|
+
python_tty-0.1.0.dist-info/top_level.txt,sha256=ZAEMWTGLkGwrlNN-lOeuJzAHB_xHAiEAecJ7CzS7FnY,11
|
|
40
|
+
python_tty-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
python_tty
|