This commit is contained in:
2026-02-13 13:45:35 -08:00
parent 6416aeceec
commit ce2f28cc50
5 changed files with 99 additions and 24 deletions

View File

@@ -47,6 +47,29 @@ import logging
logger = logging.getLogger(__name__)
_RESULT_TABLE_ROW_STYLE_LOOP: List[tuple[str, str]] = [
("#ff0000", "#8f00ff"),
("#ffa500", "#800080"),
("#ffff00", "#0000ff"),
("#808080", "#008000"),
("#008000", "#808080"),
("#0000ff", "#ffff00"),
("#800080", "#ffa500"),
("#8f00ff", "#ff0000"),
("#ffffff", "#000000"),
]
RESULT_TABLE_HEADER_STYLE = "bold #000000 on #ffffff"
RESULT_TABLE_BORDER_STYLE = "#000000 on #ffffff"
def get_result_table_row_style(row_index: int) -> str:
text_color, bg_color = _RESULT_TABLE_ROW_STYLE_LOOP[
row_index % len(_RESULT_TABLE_ROW_STYLE_LOOP)
]
return f"{text_color} on {bg_color}"
def _sanitize_cell_text(value: Any) -> str:
"""Coerce to a single-line, tab-free string suitable for terminal display."""
if value is None:
@@ -1194,10 +1217,11 @@ class Table:
if path_obj.suffix:
extension = path_obj.suffix.lstrip(".")
visible_data[title_field] = path_obj.stem
visible_data["ext"] = extension
# Preserve ext extracted from payload/metadata when present.
# Only use title suffix as fallback when ext is missing.
if not str(visible_data.get("ext") or "").strip():
visible_data["ext"] = extension
# print(f"DEBUG: Split extension. Title: {visible_data[title_field]}, Ext: {extension}")
else:
visible_data["ext"] = ""
# Ensure 'ext' is present so it gets picked up by priority_groups in correct order
if "ext" not in visible_data:
@@ -1345,7 +1369,15 @@ class Table:
"""Return a Rich renderable representing this table."""
if not self.rows:
empty = Text("No results")
return Panel(empty, title=self.title) if self.title else empty
return (
Panel(
empty,
title=Text(str(self.title), style=RESULT_TABLE_HEADER_STYLE),
border_style=RESULT_TABLE_BORDER_STYLE,
)
if self.title
else empty
)
col_names: List[str] = []
seen: Set[str] = set()
@@ -1357,7 +1389,8 @@ class Table:
table = RichTable(
show_header=True,
header_style="bold",
header_style=RESULT_TABLE_HEADER_STYLE,
border_style=RESULT_TABLE_BORDER_STYLE,
box=SIMPLE,
expand=True,
show_lines=False,
@@ -1387,12 +1420,20 @@ class Table:
for name in col_names:
val = row.get_column(name) or ""
cells.append(self._apply_value_case(_sanitize_cell_text(val)))
table.add_row(*cells)
table.add_row(*cells, style=get_result_table_row_style(row_idx - 1))
if self.title or self.header_lines:
header_bits = [Text(line) for line in (self.header_lines or [])]
renderable = Group(*header_bits, table) if header_bits else table
return Panel(renderable, title=self.title) if self.title else renderable
return (
Panel(
renderable,
title=Text(str(self.title), style=RESULT_TABLE_HEADER_STYLE),
border_style=RESULT_TABLE_BORDER_STYLE,
)
if self.title
else renderable
)
return table
@@ -2233,16 +2274,21 @@ class ItemDetailView(Table):
detail_title = str(self.detail_title or "Item Details").strip() or "Item Details"
elements.append(Panel(
details_table,
title=f"[bold green]{detail_title}[/bold green]",
border_style="green",
title=Text(detail_title, style=RESULT_TABLE_HEADER_STYLE),
border_style=RESULT_TABLE_BORDER_STYLE,
padding=(1, 2)
))
if results_renderable:
# If it's a Panel already (from super().to_rich() with title), use it directly
# but force the border style to green for consistency
# but force the border style to the result-table standard for consistency
if isinstance(results_renderable, Panel):
results_renderable.border_style = "green"
results_renderable.border_style = RESULT_TABLE_BORDER_STYLE
if results_renderable.title:
results_renderable.title = Text(
str(results_renderable.title),
style=RESULT_TABLE_HEADER_STYLE,
)
# Add a bit of padding inside if it contains a table
elements.append(results_renderable)
else:
@@ -2253,6 +2299,12 @@ class ItemDetailView(Table):
# Add a bit of padding
results_group = Group(Text(""), results_renderable, Text(""))
elements.append(Panel(results_group, title=display_title, border_style="green"))
elements.append(
Panel(
results_group,
title=Text(str(display_title), style=RESULT_TABLE_HEADER_STYLE),
border_style=RESULT_TABLE_BORDER_STYLE,
)
)
return Group(*elements)

View File

@@ -12,6 +12,11 @@ import logging
logger = logging.getLogger(__name__)
from SYS.result_table import (
RESULT_TABLE_BORDER_STYLE,
RESULT_TABLE_HEADER_STYLE,
get_result_table_row_style,
)
from SYS.result_table_api import ColumnSpec, ResultModel, ResultTable, Renderer
@@ -30,12 +35,16 @@ class RichRenderer(Renderer):
except Exception as exc:
raise RuntimeError("rich is required for RichRenderer") from exc
table = RichTable(show_header=True, header_style="bold")
table = RichTable(
show_header=True,
header_style=RESULT_TABLE_HEADER_STYLE,
border_style=RESULT_TABLE_BORDER_STYLE,
)
cols = list(columns)
for col in cols:
table.add_column(col.header)
for r in rows:
for row_idx, r in enumerate(rows):
cells = []
for col in cols:
try:
@@ -52,7 +61,7 @@ class RichRenderer(Renderer):
logger.exception("Column extractor failed for '%s': %s", col.header, exc)
cell = ""
cells.append(cell)
table.add_row(*cells)
table.add_row(*cells, style=get_result_table_row_style(row_idx))
return table