dfd
This commit is contained in:
@@ -175,6 +175,8 @@ class ResultTable:
|
||||
"""Command that generated this table (e.g., 'download-data URL')"""
|
||||
self.source_args: List[str] = []
|
||||
"""Base arguments for the source command"""
|
||||
self.header_lines: List[str] = []
|
||||
"""Optional metadata lines rendered under the title"""
|
||||
|
||||
def add_row(self) -> ResultRow:
|
||||
"""Add a new row to the table and return it for configuration."""
|
||||
@@ -211,6 +213,34 @@ class ResultTable:
|
||||
"""
|
||||
if 0 <= row_index < len(self.rows):
|
||||
self.rows[row_index].selection_args = selection_args
|
||||
|
||||
def set_header_lines(self, lines: List[str]) -> "ResultTable":
|
||||
"""Attach metadata lines that render beneath the title."""
|
||||
self.header_lines = [line for line in lines if line]
|
||||
return self
|
||||
|
||||
def set_header_line(self, line: str) -> "ResultTable":
|
||||
"""Attach a single metadata line beneath the title."""
|
||||
return self.set_header_lines([line] if line else [])
|
||||
|
||||
def set_storage_summary(self, storage_counts: Dict[str, int], filter_text: Optional[str] = None, inline: bool = False) -> str:
|
||||
"""Render a storage count summary (e.g., "Hydrus:0 Local:1 | filter: \"q\"").
|
||||
|
||||
Returns the summary string so callers can place it inline with the title if desired.
|
||||
"""
|
||||
summary_parts: List[str] = []
|
||||
|
||||
if storage_counts:
|
||||
summary_parts.append(" ".join(f"{name}:{count}" for name, count in storage_counts.items()))
|
||||
|
||||
if filter_text:
|
||||
safe_filter = filter_text.replace("\"", "\\\"")
|
||||
summary_parts.append(f'filter: "{safe_filter}"')
|
||||
|
||||
summary = " | ".join(summary_parts)
|
||||
if not inline:
|
||||
self.set_header_line(summary)
|
||||
return summary
|
||||
|
||||
def add_result(self, result: Any) -> "ResultTable":
|
||||
"""Add a result object (SearchResult, PipeObject, ResultItem, TagItem, or dict) as a row.
|
||||
@@ -249,7 +279,14 @@ class ResultTable:
|
||||
|
||||
def _add_search_result(self, row: ResultRow, result: Any) -> None:
|
||||
"""Extract and add SearchResult fields to row."""
|
||||
# Core fields
|
||||
# If provider supplied explicit columns, render those and skip legacy defaults
|
||||
cols = getattr(result, "columns", None)
|
||||
if cols:
|
||||
for name, value in cols:
|
||||
row.add_column(name, value)
|
||||
return
|
||||
|
||||
# Core fields (legacy fallback)
|
||||
title = getattr(result, 'title', '')
|
||||
origin = getattr(result, 'origin', '').lower()
|
||||
|
||||
@@ -597,6 +634,9 @@ class ResultTable:
|
||||
lines.append("=" * self.title_width)
|
||||
lines.append(self.title.center(self.title_width))
|
||||
lines.append("=" * self.title_width)
|
||||
|
||||
if self.header_lines:
|
||||
lines.extend(self.header_lines)
|
||||
|
||||
# Add header with # column
|
||||
header_parts = ["#".ljust(num_width)]
|
||||
|
||||
Reference in New Issue
Block a user