This commit is contained in:
2026-06-28 22:10:55 -07:00
parent d309c3da93
commit c97f3df288
3 changed files with 106 additions and 9 deletions
+40 -1
View File
@@ -15,6 +15,7 @@ from __future__ import annotations
from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional, Callable, Set, Tuple
from pathlib import Path
from urllib.parse import urlparse
import json
import re
@@ -2546,6 +2547,44 @@ class ItemDetailView(Table):
return any(_has_renderable_value(item) for item in value)
return True
def _looks_like_http_url(value: Any) -> bool:
text = str(value or "").strip().lower()
return text.startswith("http://") or text.startswith("https://")
def _short_link_label(url_value: str, *, max_len: int = 68) -> str:
text = str(url_value or "").strip()
if not text:
return ""
parsed = urlparse(text)
host = (parsed.netloc or "").strip()
path = (parsed.path or "").strip()
leaf = path.rstrip("/").split("/")[-1] if path else ""
if host and leaf:
label = f"{host}/.../{leaf}"
elif host and path:
label = f"{host}{path}"
elif host:
label = host
else:
label = text
if parsed.query:
label = f"{label}?..."
if len(label) > max_len:
return f"{label[:max_len - 3]}..."
return label
def _render_detail_value(key: str, value: Any) -> Any:
# Keep terminal links compact while preserving full click target.
if str(key or "").strip().lower() in {"path", "url"} and _looks_like_http_url(value):
full_url = str(value).strip()
label = _short_link_label(full_url)
return _rich().Text(label, style=f"underline cyan link {full_url}")
return str(value)
# Canonical display order for metadata; plugin-specific detail views can
# prepend a preferred order without needing to reimplement rendering.
order: List[str] = []
@@ -2580,7 +2619,7 @@ class ItemDetailView(Table):
val = "\n".join([f"[dim]→[/dim] {r}" for r in val])
if _has_renderable_value(val):
details_table.add_row(f"{key}:", str(val))
details_table.add_row(f"{key}:", _render_detail_value(key, val))
has_details = True
# Add any remaining metadata not in the canonical list