updating and refining plugin system refactor

This commit is contained in:
2026-04-28 22:20:54 -07:00
parent 8685fbb723
commit 323c24f4f4
33 changed files with 4287 additions and 3312 deletions
+82 -4
View File
@@ -3,8 +3,41 @@ from __future__ import annotations
from typing import Any, Iterable, Optional, Sequence
_ACRONYM_LABELS = {
"id": "ID",
"ids": "IDs",
"url": "URL",
"urls": "URLs",
"api": "API",
"http": "HTTP",
"https": "HTTPS",
"ftp": "FTP",
"ftps": "FTPS",
"scp": "SCP",
"ssh": "SSH",
"ip": "IP",
"mpv": "MPV",
}
def _labelize_key(key: str) -> str:
return str(key or "").replace("_", " ").title()
parts = [part for part in str(key or "").replace("_", " ").split() if part]
normalized: list[str] = []
for part in parts:
lowered = part.lower()
normalized.append(_ACRONYM_LABELS.get(lowered, part.title()))
return " ".join(normalized)
def _has_display_value(value: Any) -> bool:
if value is None:
return False
if isinstance(value, str):
text = value.strip()
return bool(text and text.lower() not in {"<null>", "null", "none"})
if isinstance(value, Sequence) and not isinstance(value, (str, bytes, bytearray)):
return any(_has_display_value(item) for item in value)
return True
def _normalize_tags_value(tags: Any) -> Optional[str]:
@@ -45,7 +78,7 @@ def prepare_detail_metadata(
if str(key).startswith("_") or key in {"selection_action", "selection_args"}:
continue
label = _labelize_key(str(key))
if label not in metadata and value is not None:
if label not in metadata and _has_display_value(value):
metadata[label] = value
if title:
@@ -62,7 +95,7 @@ def prepare_detail_metadata(
metadata["Tags"] = tags_text
for key, value in (extra_fields or {}).items():
if value is not None:
if _has_display_value(value):
metadata[str(key)] = value
return metadata
@@ -77,6 +110,7 @@ def create_detail_view(
init_command: Optional[tuple[str, Sequence[str]]] = None,
max_columns: Optional[int] = None,
exclude_tags: bool = False,
detail_order: Optional[Sequence[str]] = None,
value_case: Optional[str] = "preserve",
perseverance: bool = True,
) -> Any:
@@ -87,6 +121,8 @@ def create_detail_view(
kwargs["max_columns"] = max_columns
if exclude_tags:
kwargs["exclude_tags"] = True
if detail_order is not None:
kwargs["detail_order"] = list(detail_order)
table = ItemDetailView(title, **kwargs)
if table_name:
@@ -101,4 +137,46 @@ def create_detail_view(
if init_command:
name, args = init_command
table = table.init_command(name, list(args))
return table
return table
def render_selection_detail_view(
*,
ctx: Any,
item: Any,
title: str,
metadata: dict[str, Any],
table_name: Optional[str] = None,
detail_order: Optional[Sequence[str]] = None,
value_case: Optional[str] = "preserve",
exclude_tags: bool = False,
) -> bool:
from SYS.rich_display import stdout_console
detail_view = create_detail_view(
title,
metadata,
table_name=table_name,
detail_order=detail_order,
value_case=value_case,
exclude_tags=exclude_tags,
)
payload = item.to_dict() if hasattr(item, "to_dict") else item
try:
if hasattr(ctx, "set_last_result_items_only") and isinstance(payload, dict):
ctx.set_last_result_items_only([payload])
except Exception:
pass
try:
try:
detail_view.title = ""
detail_view.header_lines = []
except Exception:
pass
stdout_console().print()
stdout_console().print(detail_view.to_rich())
except Exception:
return False
return True