h
This commit is contained in:
@@ -262,100 +262,20 @@ def render_image_to_console(image_path: str | Path, max_width: int | None = None
|
||||
|
||||
|
||||
def render_item_details_panel(item: Dict[str, Any]) -> None:
|
||||
"""Render a comprehensive details panel for a result item."""
|
||||
from rich.table import Table
|
||||
from rich.columns import Columns
|
||||
from rich.panel import Panel
|
||||
|
||||
title = (
|
||||
item.get("title")
|
||||
or item.get("name")
|
||||
or item.get("TITLE")
|
||||
or "Unnamed Item"
|
||||
)
|
||||
|
||||
# Main layout table for the panel
|
||||
details_table = Table.grid(expand=True, padding=(0, 2))
|
||||
details_table.add_column(style="cyan", no_wrap=True, width=15, justify="right")
|
||||
details_table.add_column(style="white")
|
||||
|
||||
# Canonical order
|
||||
details_table.add_row("Title:", f"[bold]{title}[/bold]")
|
||||
"""Render a comprehensive details panel for a result item using unified ItemDetailView."""
|
||||
from SYS.result_table import ItemDetailView, extract_item_metadata
|
||||
|
||||
if "hash" in item or "hash_hex" in item or "file_hash" in item:
|
||||
h = item.get("hash") or item.get("hash_hex") or item.get("file_hash")
|
||||
details_table.add_row("Hash:", str(h))
|
||||
|
||||
if "store" in item or "table" in item:
|
||||
s = item.get("store") or item.get("table")
|
||||
details_table.add_row("Store:", str(s))
|
||||
metadata = extract_item_metadata(item)
|
||||
|
||||
if "path" in item or "target" in item:
|
||||
path = item.get("path") or item.get("target")
|
||||
# Only show if it doesn't look like a URL (which would go in Url row)
|
||||
if path and not str(path).startswith(("http://", "https://")):
|
||||
details_table.add_row("Path:", str(path))
|
||||
# Create a specialized view with no results rows (only the metadata panel)
|
||||
# We set no_choice=True to hide the "#" column (not that there are any rows).
|
||||
view = ItemDetailView(item_metadata=metadata).set_no_choice(True)
|
||||
|
||||
if "ext" in item or "extension" in item:
|
||||
ext = item.get("ext") or item.get("extension")
|
||||
details_table.add_row("Ext:", str(ext))
|
||||
|
||||
if "size_bytes" in item or "size" in item:
|
||||
size = item.get("size_bytes") or item.get("size")
|
||||
if isinstance(size, (int, float, str)) and str(size).isdigit():
|
||||
size = int(size)
|
||||
if size > 1024 * 1024 * 1024:
|
||||
size_str = f"{size / (1024*1024*1024):.1f} GB"
|
||||
elif size > 1024 * 1024:
|
||||
size_str = f"{size / (1024*1024):.1f} MB"
|
||||
elif size > 1024:
|
||||
size_str = f"{size / 1024:.1f} KB"
|
||||
else:
|
||||
size_str = f"{size} bytes"
|
||||
details_table.add_row("Size:", size_str)
|
||||
|
||||
# URL(s)
|
||||
urls = item.get("url") or item.get("URL") or []
|
||||
if isinstance(urls, str):
|
||||
urls = [urls]
|
||||
valid_urls = [str(u).strip() for u in urls if str(u).strip()]
|
||||
if valid_urls:
|
||||
url_text = "\n".join(valid_urls)
|
||||
details_table.add_row("Url:", url_text)
|
||||
else:
|
||||
details_table.add_row("Url:", "[dim]<null>[/dim]")
|
||||
|
||||
# Tags
|
||||
tags = item.get("tag") or item.get("tags") or []
|
||||
if isinstance(tags, str):
|
||||
tags = [t.strip() for t in tags.split(",") if t.strip()]
|
||||
if isinstance(tags, list) and tags:
|
||||
tags_sorted = sorted(map(str, tags))
|
||||
tag_cols = Columns([f"[dim]#[/dim]{t}" for t in tags_sorted], equal=True, expand=True)
|
||||
details_table.add_row("", "") # Spacer
|
||||
details_table.add_row("Tags:", tag_cols)
|
||||
|
||||
# Relationships (if any)
|
||||
rels = item.get("relationships") or item.get("rel") or []
|
||||
if isinstance(rels, list) and rels:
|
||||
# Check for list of dicts (from get-relationship) or list of strings
|
||||
if rels and isinstance(rels[0], dict):
|
||||
rel_text = "\n".join([f"[dim]→[/dim] {r.get('type','rel')}: {r.get('title','?')}" for r in rels])
|
||||
else:
|
||||
rel_text = "\n".join([f"[dim]→[/dim] {r}" for r in rels])
|
||||
details_table.add_row("Relations:", rel_text)
|
||||
else:
|
||||
details_table.add_row("Relations:", "[dim]<null>[/dim]")
|
||||
|
||||
panel = Panel(
|
||||
details_table,
|
||||
title=f"[bold green]Item Details[/bold green]",
|
||||
border_style="green",
|
||||
padding=(1, 2),
|
||||
expand=True
|
||||
)
|
||||
# We want to print ONLY the elements from ItemDetailView, so we don't use stdout_console().print(view)
|
||||
# as that would include the (empty) results panel.
|
||||
# Actually, let's just use to_rich and print it.
|
||||
|
||||
stdout_console().print()
|
||||
stdout_console().print(panel)
|
||||
stdout_console().print(view.to_rich())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user