f
This commit is contained in:
95
CLI.py
95
CLI.py
@@ -33,7 +33,13 @@ from rich.panel import Panel
|
||||
from rich.markdown import Markdown
|
||||
from rich.bar import Bar
|
||||
from rich.table import Table
|
||||
from SYS.rich_display import stderr_console, stdout_console
|
||||
from SYS.rich_display import (
|
||||
IMAGE_EXTENSIONS,
|
||||
render_image_to_console,
|
||||
render_item_details_panel,
|
||||
stderr_console,
|
||||
stdout_console,
|
||||
)
|
||||
|
||||
|
||||
def _install_rich_traceback(*, show_locals: bool = False) -> None:
|
||||
@@ -4138,6 +4144,93 @@ class PipelineExecutor:
|
||||
ctx.set_last_result_items_only(items)
|
||||
return
|
||||
|
||||
# Special-case: selecting a single image should show it directly.
|
||||
if len(items) == 1:
|
||||
item = items[0]
|
||||
|
||||
# Try to get hash and store to resolve through the backend
|
||||
file_hash = None
|
||||
store_name = None
|
||||
if isinstance(item, dict):
|
||||
file_hash = item.get("hash")
|
||||
store_name = item.get("store")
|
||||
else:
|
||||
if hasattr(item, "hash"):
|
||||
file_hash = getattr(item, "hash", None)
|
||||
if hasattr(item, "store"):
|
||||
store_name = getattr(item, "store", None)
|
||||
|
||||
# Try to resolve the file through the Store backend if we have hash + store
|
||||
resolved_file_path = None
|
||||
if file_hash and store_name:
|
||||
try:
|
||||
from Store import Store
|
||||
storage = Store(config=config or {})
|
||||
backend = storage[str(store_name)]
|
||||
|
||||
# Call get_file to resolve the hash to an actual file path
|
||||
maybe_path = backend.get_file(str(file_hash))
|
||||
|
||||
if isinstance(maybe_path, Path):
|
||||
resolved_file_path = maybe_path
|
||||
elif isinstance(maybe_path, str) and maybe_path:
|
||||
# Only treat as a Path if it doesn't look like a URL
|
||||
if not maybe_path.startswith(("http://", "https://")):
|
||||
resolved_file_path = Path(maybe_path)
|
||||
except Exception:
|
||||
# Fallback: try using the path field from the item
|
||||
pass
|
||||
|
||||
# If backend resolution failed, try the path field
|
||||
if not resolved_file_path:
|
||||
path_str = None
|
||||
if isinstance(item, dict):
|
||||
path_str = (
|
||||
item.get("path")
|
||||
or item.get("PATH")
|
||||
or item.get("target")
|
||||
or item.get("filename")
|
||||
)
|
||||
else:
|
||||
# Try attributes for PipeObject/SearchResult/etc.
|
||||
for attr in ("path", "PATH", "target", "filename"):
|
||||
if hasattr(item, attr):
|
||||
val = getattr(item, attr)
|
||||
if val and isinstance(val, (str, Path)):
|
||||
path_str = val
|
||||
break
|
||||
|
||||
if path_str:
|
||||
from SYS.utils import expand_path
|
||||
resolved_file_path = expand_path(path_str).resolve()
|
||||
|
||||
# Now check if it's an image and render it
|
||||
is_image = False
|
||||
if resolved_file_path:
|
||||
try:
|
||||
if resolved_file_path.suffix.lower() in IMAGE_EXTENSIONS and resolved_file_path.exists():
|
||||
# Use our image renderer
|
||||
stdout_console().print()
|
||||
render_image_to_console(resolved_file_path)
|
||||
is_image = True
|
||||
elif resolved_file_path.suffix.lower() in IMAGE_EXTENSIONS and not resolved_file_path.exists():
|
||||
stdout_console().print(f"[yellow]Warning: Image file not found at {resolved_file_path}[/yellow]")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Render the comprehensive details panel for the item in either case
|
||||
item_to_details = item if isinstance(item, dict) else (
|
||||
item.to_dict() if hasattr(item, "to_dict") else vars(item)
|
||||
)
|
||||
# Ensure we include the resolved path if we found one
|
||||
if resolved_file_path and "path" not in item_to_details:
|
||||
item_to_details["path"] = str(resolved_file_path)
|
||||
|
||||
render_item_details_panel(item_to_details)
|
||||
|
||||
ctx.set_last_result_items_only(items)
|
||||
return
|
||||
|
||||
table = ResultTable("Selection Result")
|
||||
for item in items:
|
||||
table.add_result(item)
|
||||
|
||||
Reference in New Issue
Block a user