This commit is contained in:
2026-01-01 20:37:27 -08:00
parent f3c79609d8
commit deb05c0d44
35 changed files with 5030 additions and 4879 deletions

View File

@@ -361,6 +361,8 @@ class ResultRow:
"""Arguments to use for this row when selected via @N syntax (e.g., ['-item', '3'])"""
source_index: Optional[int] = None
"""Original insertion order index (used to map sorted views back to source items)."""
payload: Optional[Any] = None
"""Original object that contributed to this row."""
def add_column(self, name: str, value: Any) -> None:
"""Add a column to this row."""
@@ -498,6 +500,9 @@ class ResultTable:
self.table: Optional[str] = None
"""Table type (e.g., 'youtube', 'soulseek') for context-aware selection logic."""
self.table_metadata: Dict[str, Any] = {}
"""Optional provider/table metadata (e.g., provider name, view)."""
self.value_case: str = "lower"
"""Display-only value casing: 'lower' (default), 'upper', or 'preserve'."""
@@ -525,6 +530,18 @@ class ResultTable:
self.table = table
return self
def set_table_metadata(self, metadata: Optional[Dict[str, Any]]) -> "ResultTable":
"""Attach provider/table metadata for downstream selection logic."""
self.table_metadata = dict(metadata or {})
return self
def get_table_metadata(self) -> Dict[str, Any]:
"""Return attached provider/table metadata (copy to avoid mutation)."""
try:
return dict(self.table_metadata)
except Exception:
return {}
def set_no_choice(self, no_choice: bool = True) -> "ResultTable":
"""Mark the table as non-interactive (no row numbers, no selection parsing)."""
self.no_choice = bool(no_choice)
@@ -612,6 +629,9 @@ class ResultTable:
new_table.input_options = dict(self.input_options) if self.input_options else {}
new_table.no_choice = self.no_choice
new_table.table = self.table
new_table.table_metadata = (
dict(self.table_metadata) if getattr(self, "table_metadata", None) else {}
)
new_table.header_lines = list(self.header_lines) if self.header_lines else []
return new_table
@@ -712,6 +732,7 @@ class ResultTable:
Self for chaining
"""
row = self.add_row()
row.payload = result
# Handle TagItem from get_tag.py (tag display with index)
if hasattr(result, "__class__") and result.__class__.__name__ == "TagItem":
@@ -738,6 +759,21 @@ class ResultTable:
return self
def get_row_payload(self, row_index: int) -> Optional[Any]:
"""Return the original payload for the row at ``row_index`` if available."""
if 0 <= row_index < len(self.rows):
return getattr(self.rows[row_index], "payload", None)
return None
def get_payloads(self) -> List[Any]:
"""Return the payloads for every row, preserving table order."""
payloads: List[Any] = []
for row in self.rows:
payload = getattr(row, "payload", None)
if payload is not None:
payloads.append(payload)
return payloads
def _add_search_result(self, row: ResultRow, result: Any) -> None:
"""Extract and add SearchResult fields to row."""
# If provider supplied explicit columns, render those and skip legacy defaults