Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ classifiers = [
]
dependencies = [
"textual[syntax]>=6.10.0",
"textual-fastdatatable>=0.14.0",
"textual-fastdatatable==0.19.0",
"pyperclip>=1.8.2",
"keyring>=24.0.0",
"docker>=7.0.0",
Expand Down
17 changes: 13 additions & 4 deletions sqlit/shared/ui/widgets_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
from rich.markup import escape
from rich.protocol import is_renderable
from rich.text import Text
from textual.coordinate import Coordinate

from textual.containers import Container
from textual.coordinate import Coordinate
from textual.events import Key
from textual.strip import Strip
from textual_fastdatatable import DataTable as FastDataTable
Expand Down Expand Up @@ -59,8 +58,18 @@ def render_line(self, y: int) -> Strip:

return self._render_line(y, scroll_x, scroll_x + width, self.rich_style)

def _get_cell_renderable(self, row_index: int, column_index: int) -> Any:
"""Format cells with plain text for NULL/bool/date values."""
def _get_cell_renderable(
self,
row_index: int,
column_index: int,
max_width: int | None = None,
) -> Any:
"""Format cells with plain text for NULL/bool/date values.

``textual-fastdatatable`` 0.19 passes the available cell width to this
hook. Keep accepting it even though sqlit's formatter currently relies
on Rich to crop the returned renderable.
"""
if row_index == -1:
return self.ordered_columns[column_index].label

Expand Down
33 changes: 33 additions & 0 deletions tests/ui/test_fastdatatable_compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Compatibility coverage for textual-fastdatatable's rendering hooks."""

import pytest
from textual.app import App, ComposeResult

from sqlit.shared.ui.widgets_tables import SqlitDataTable


class _TableApp(App[None]):
def __init__(self, table: SqlitDataTable) -> None:
super().__init__()
self.table = table

def compose(self) -> ComposeResult:
yield self.table


def test_cell_renderable_accepts_width_from_fastdatatable_019() -> None:
"""0.19 passes the available width to subclass cell renderers."""
table = SqlitDataTable(data={"id": [1]})

renderable = table._get_cell_renderable(-1, 0, max_width=10)

assert getattr(renderable, "plain", renderable) == "id"


@pytest.mark.asyncio
async def test_table_renders_with_fastdatatable_019_width_argument() -> None:
"""Rendering a result table must not crash when 0.19 supplies max_width."""
table = SqlitDataTable(data={"id": list(range(100))})

async with _TableApp(table).run_test(size=(40, 10)):
assert "id" in table.render_line(0).text
Loading
Loading