kllk
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
This commit is contained in:
99
CLI.py
99
CLI.py
@@ -27,7 +27,12 @@ from prompt_toolkit.completion import Completer, Completion
|
||||
from prompt_toolkit.document import Document
|
||||
from prompt_toolkit.lexers import Lexer
|
||||
from prompt_toolkit.styles import Style
|
||||
|
||||
from rich.console import Console
|
||||
from rich.layout import Layout
|
||||
from rich.panel import Panel
|
||||
from rich.markdown import Markdown
|
||||
from rich.bar import Bar
|
||||
from rich.table import Table
|
||||
from rich_display import stderr_console, stdout_console
|
||||
|
||||
|
||||
@@ -466,9 +471,9 @@ class CmdletIntrospection:
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
def cmdlet_args(cmd_name: str) -> List[str]:
|
||||
def cmdlet_args(cmd_name: str, config: Optional[Dict[str, Any]] = None) -> List[str]:
|
||||
try:
|
||||
return get_cmdlet_arg_flags(cmd_name) or []
|
||||
return get_cmdlet_arg_flags(cmd_name, config=config) or []
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
@@ -551,13 +556,13 @@ class CmdletCompleter(Completer):
|
||||
self.cmdlet_names = CmdletIntrospection.cmdlet_names()
|
||||
|
||||
@staticmethod
|
||||
def _used_arg_logicals(cmd_name: str, stage_tokens: List[str]) -> Set[str]:
|
||||
def _used_arg_logicals(cmd_name: str, stage_tokens: List[str], config: Dict[str, Any]) -> Set[str]:
|
||||
"""Return logical argument names already used in this cmdlet stage.
|
||||
|
||||
Example: if the user has typed `download-media -url ...`, then `url`
|
||||
is considered used and should not be suggested again (even as `--url`).
|
||||
"""
|
||||
arg_flags = CmdletIntrospection.cmdlet_args(cmd_name)
|
||||
arg_flags = CmdletIntrospection.cmdlet_args(cmd_name, config)
|
||||
allowed = {a.lstrip("-").strip().lower() for a in arg_flags if a}
|
||||
if not allowed:
|
||||
return set()
|
||||
@@ -598,6 +603,8 @@ class CmdletCompleter(Completer):
|
||||
if ends_with_space:
|
||||
cmd_name = current.replace("_", "-")
|
||||
|
||||
config = self._config_loader.load()
|
||||
|
||||
if cmd_name == "help":
|
||||
for cmd in self.cmdlet_names:
|
||||
yield Completion(cmd, start_position=0)
|
||||
@@ -606,7 +613,7 @@ class CmdletCompleter(Completer):
|
||||
if cmd_name not in self.cmdlet_names:
|
||||
return
|
||||
|
||||
arg_names = CmdletIntrospection.cmdlet_args(cmd_name)
|
||||
arg_names = CmdletIntrospection.cmdlet_args(cmd_name, config)
|
||||
logical_seen: Set[str] = set()
|
||||
for arg in arg_names:
|
||||
arg_low = arg.lower()
|
||||
@@ -645,8 +652,8 @@ class CmdletCompleter(Completer):
|
||||
yield Completion(choice, start_position=-len(current_token))
|
||||
return
|
||||
|
||||
arg_names = CmdletIntrospection.cmdlet_args(cmd_name)
|
||||
used_logicals = self._used_arg_logicals(cmd_name, stage_tokens)
|
||||
arg_names = CmdletIntrospection.cmdlet_args(cmd_name, config)
|
||||
used_logicals = self._used_arg_logicals(cmd_name, stage_tokens, config)
|
||||
logical_seen: Set[str] = set()
|
||||
for arg in arg_names:
|
||||
arg_low = arg.lower()
|
||||
@@ -2722,21 +2729,77 @@ class MedeiaCLI:
|
||||
self.build_app()()
|
||||
|
||||
def run_repl(self) -> None:
|
||||
Welcome = """
|
||||
# MEDIOS-MACINA
|
||||
#console = Console(width=100)
|
||||
|
||||
[red]Romans 1:22[/red] Professing themselves to be wise, they became fools,
|
||||
# Valid Rich rainbow colors
|
||||
RAINBOW = [
|
||||
"red",
|
||||
"dark_orange",
|
||||
"yellow",
|
||||
"green",
|
||||
"blue",
|
||||
"purple",
|
||||
"magenta",
|
||||
]
|
||||
|
||||
def rainbow_pillar(colors, height=21, bar_width=36):
|
||||
table = Table.grid(padding=0)
|
||||
table.add_column(no_wrap=True)
|
||||
|
||||
dfd
|
||||
==
|
||||
Rich can do a pretty *decent* job of rendering markdown.
|
||||
for i in range(height):
|
||||
color = colors[i % len(colors)]
|
||||
table.add_row(Bar(size=1, begin=0, end=1, width=bar_width, color=color))
|
||||
|
||||
1. This is a list item
|
||||
2. This is another list item
|
||||
return table
|
||||
|
||||
# Build root layout
|
||||
root = Layout(name="root")
|
||||
root.split_row(
|
||||
Layout(name="left", ratio=2),
|
||||
Layout(name="center", ratio=8),
|
||||
Layout(name="right", ratio=2),
|
||||
)
|
||||
|
||||
# Left pillar → forward rainbow
|
||||
root["left"].update(
|
||||
Panel(rainbow_pillar(RAINBOW, height=21, bar_width=36), title="DELTA")
|
||||
)
|
||||
|
||||
# Right pillar → reverse rainbow
|
||||
root["right"].update(
|
||||
Panel(rainbow_pillar(list(reversed(RAINBOW)), height=21, bar_width=36), title="LAMBDA")
|
||||
)
|
||||
|
||||
# Center content
|
||||
center_md = Markdown(
|
||||
"""
|
||||
# ****************** Medios Macina ******************
|
||||
take what you want | keep what you like | share what you love
|
||||
_____________________________________________________________
|
||||
_____________________________________________________________
|
||||
_____________________________________________________________
|
||||
For suddenly you may be let loose from the net, and thrown out to sea.
|
||||
Waving around clutching at gnats, unable to lift the heavy anchor. Lost
|
||||
and without a map, forgotten things from the past by distracting wind storms.
|
||||
_____________________________________________________________
|
||||
_____________________________________________________________
|
||||
_____________________________________________________________
|
||||
Light shines a straight path to the golden shores.
|
||||
Come to love it when others take what you share, as there is no greater joy
|
||||
"""
|
||||
md = Markdown(Welcome)
|
||||
console.print(md)
|
||||
)
|
||||
root["center"].update(Panel(center_md, title="KAPPA", height=21))
|
||||
|
||||
console.print(root)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
prompt_text = "<🜂🜄|🜁🜃>"
|
||||
|
||||
startup_table = ResultTable(
|
||||
|
||||
Reference in New Issue
Block a user