Skip to content

Unable to use CSS variable in markup within DataTable #6273

@anlar

Description

@anlar

When using markup language to display text it is possible to use CSS variables (eg [$success]Success text[/]). This works fine in labels, but not in DataTable rows - there I could only use markup like [green]Green text[/].

Example application:

from textual.app import App, ComposeResult
from textual.widgets import DataTable, Label

class TableApp(App):
    examples = [
            '1 Simple text',
            '2 [bold]Bold text[/]',
            '3 [green]Green text[/]',
            '4 [bold green]Bold green text[/]',
            '5 [$success]Success text[/]',  # this will fail in table
            '6 [bold $success]Bold success text[/]',
            ]

    def compose(self) -> ComposeResult:
        for ex in self.examples:
            yield Label(ex)
        yield DataTable(cursor_type='none')

    def on_mount(self) -> None:
        table = self.query_one(DataTable)
        table.add_columns('Table Column')
        for ex in self.examples:
            if not ex.startswith('5'):
                table.add_row(ex)

app = TableApp()

if __name__ == "__main__":
    app.run()

Result (observe that last row in table is not styled with $success):

Image

Textual Diagnostics

Versions

Name Value
Textual 6.7.1
Rich 14.2.0

Python

Name Value
Version 3.12.3
Implementation CPython
Compiler GCC 13.3.0
Executable /home/anlar/dev/anlar/tewi/venv/bin/python3

Operating System

Name Value
System Linux
Release 6.14.0-36-generic
Version #36~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Oct 15 15:45:17 UTC 2

Terminal

Name Value
Terminal Application tmux (3.4)
TERM tmux-256color
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=173, height=40
legacy_windows False
min_width 1
max_width 173
is_terminal True
encoding utf-8
max_height 40
justify None
overflow None
no_wrap False
highlight None
markup None
height None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions