hh
This commit is contained in:
@@ -323,10 +323,21 @@ def _emit_tags_as_table(
|
||||
"""
|
||||
from SYS.result_table import ItemDetailView, extract_item_metadata
|
||||
|
||||
# Prepare metadata for the detail view
|
||||
metadata = extract_item_metadata(subject)
|
||||
# Prepare metadata for the detail view, extracting all fields from subject first
|
||||
metadata = extract_item_metadata(subject) or {}
|
||||
|
||||
# Overlays/Overrides from explicit args if subject was partial
|
||||
# Preserve all additional fields from subject dict if it's a dict-like object
|
||||
if isinstance(subject, dict):
|
||||
for key, value in subject.items():
|
||||
# Skip internal/control fields
|
||||
if not key.startswith("_") and key not in {"selection_action", "selection_args"}:
|
||||
# Convert keys to readable labels (snake_case -> Title Case)
|
||||
label = str(key).replace("_", " ").title()
|
||||
# Only add if not already present from extract_item_metadata
|
||||
if label not in metadata and value is not None:
|
||||
metadata[label] = value
|
||||
|
||||
# Apply explicit parameter overrides (these take priority)
|
||||
if item_title:
|
||||
metadata["Title"] = item_title
|
||||
if file_hash:
|
||||
@@ -341,7 +352,7 @@ def _emit_tags_as_table(
|
||||
table = ItemDetailView("Tags", item_metadata=metadata, max_columns=1, exclude_tags=True)
|
||||
table.set_source_command("get-tag", [])
|
||||
|
||||
# Create TagItem for each tag
|
||||
# Create TagItem for each tag and add to table
|
||||
tag_items = []
|
||||
for idx, tag_name in enumerate(tags_list, start=1):
|
||||
tag_item = TagItem(
|
||||
@@ -356,38 +367,38 @@ def _emit_tags_as_table(
|
||||
table.add_result(tag_item)
|
||||
# Also emit to pipeline for downstream processing
|
||||
ctx.emit(tag_item)
|
||||
|
||||
# Store the table and items in history so @.. works to go back
|
||||
# Use overlay mode so it doesn't push the previous search to history stack
|
||||
# This makes get-tag behave like a transient view
|
||||
table_applied = False
|
||||
try:
|
||||
ctx.set_last_result_table_overlay(table, tag_items, subject)
|
||||
table_applied = True
|
||||
except AttributeError:
|
||||
try:
|
||||
ctx.set_last_result_table(table, tag_items, subject)
|
||||
table_applied = True
|
||||
except Exception:
|
||||
table_applied = False
|
||||
except Exception:
|
||||
table_applied = False
|
||||
|
||||
# Display the rich panel (metadata info) if not in quiet/emit-only mode.
|
||||
# In the TUI, this output is captured and shown in the log pane.
|
||||
|
||||
# Mark that items were already added to the table
|
||||
setattr(table, "_items_added", True)
|
||||
|
||||
# Display the table and persist for @N selection
|
||||
if not quiet:
|
||||
try:
|
||||
from SYS.rich_display import stdout_console
|
||||
stdout_console().print(table)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if table_applied:
|
||||
try:
|
||||
if hasattr(ctx, "set_current_stage_table"):
|
||||
ctx.set_current_stage_table(table)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Use the shared helper to persist the table for @N selection
|
||||
try:
|
||||
from cmdlet._shared import display_and_persist_items
|
||||
# Skip panel rendering since table already exists with custom ItemDetailView
|
||||
display_and_persist_items(
|
||||
tag_items,
|
||||
title=table.title if hasattr(table, 'title') else "Tags",
|
||||
subject=subject,
|
||||
display_type="custom",
|
||||
table=table,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Also update the current stage table for TUI
|
||||
try:
|
||||
if hasattr(ctx, "set_current_stage_table"):
|
||||
ctx.set_current_stage_table(table)
|
||||
except Exception:
|
||||
pass
|
||||
# Note: CLI will handle displaying the table via ResultTable formatting
|
||||
|
||||
|
||||
@@ -1705,6 +1716,11 @@ def _run_impl(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
# For store-backed items (Hydrus/Folders), we want the latest state.
|
||||
if display_tags and not emit_mode and not is_store_backed:
|
||||
subject_payload = _subject_payload_with(display_tags)
|
||||
# Merge the full result object into subject_payload so all original metadata is preserved
|
||||
if isinstance(result, dict):
|
||||
for key, value in result.items():
|
||||
if key not in subject_payload and not key.startswith("_"):
|
||||
subject_payload[key] = value
|
||||
_emit_tags_as_table(
|
||||
display_tags,
|
||||
file_hash=file_hash,
|
||||
@@ -1739,6 +1755,12 @@ def _run_impl(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
current,
|
||||
service_name if source == "hydrus" else None,
|
||||
)
|
||||
# Merge the full result object into subject_payload so all original metadata is preserved
|
||||
# (e.g., url, source_url, etc. from search results)
|
||||
if isinstance(result, dict):
|
||||
for key, value in result.items():
|
||||
if key not in subject_payload and not key.startswith("_"):
|
||||
subject_payload[key] = value
|
||||
_emit_tags_as_table(
|
||||
current,
|
||||
file_hash=file_hash,
|
||||
|
||||
Reference in New Issue
Block a user