Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rich renderables in rich table are not correctly displayed #2120

Closed
bobatsar opened this issue Mar 23, 2023 · 4 comments
Closed

rich renderables in rich table are not correctly displayed #2120

bobatsar opened this issue Mar 23, 2023 · 4 comments

Comments

@bobatsar
Copy link

bobatsar commented Mar 23, 2023

As discussed in #1348 coloring inside a rich table is not working out of the box in textual.
To print the colors correctly, there is a workaround to use Text.from_markup.

When trying to include hyperlinks with the rich [link] markup, it was also not correctly rendered in my case.

I realized when writing the example, that it is important to apply Text.from_markup as last operation before adding it to the table. If an already modified from_markup(text) is used in a string interpolation, it is not working any longer.

Is it possible to handle rich markup in renderables directly without the from_markup workaround?

from textual.app import App, ComposeResult
from textual.widgets import Static
from rich.table import Table
from rich import print
from rich.text import Text


def do_nothing(a):
    return a


def rich_table(title="", from_markup_working=True, raw=False):
    t = Table()

    from_markup = do_nothing if raw else Text.from_markup

    if from_markup_working:
        t.title = from_markup(f"{title}\n[link=https://www.willmcgugan.com]blog[/link]")
    else:
        link = from_markup("[link=https://www.willmcgugan.com]blog[/link]")
        t.title = f"{title}\n{link}"

    t.add_column("First")
    t.add_column("Second")

    t.add_row("1", "2")
    t.add_row("[red]1[/red]", "[green]2[/green]")
    t.add_row(from_markup("[red]1[/red]"), from_markup("[green]2[/green]"))
    t.add_row(
        "[link=https://www.willmcgugan.com]blog[/link]",
        from_markup("[link=https://www.willmcgugan.com]blog[/link]"),
    )
    return t


rich_tables = [
    rich_table(
        title="Direct markup not working in textual but working in plain rich",
        raw=True,
        from_markup_working=False,
    ),
    rich_table(
        title="Link in title not working. From markup not last operation",
        from_markup_working=False,
    ),
    rich_table("from_markup correctly used for title", from_markup_working=True),
]


class WelcomeApp(App):
    def compose(self) -> ComposeResult:
        for t in rich_tables:
            yield Static(t)


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

    for t in rich_tables:
        print(t)

Bildschirmfoto vom 2023-03-23 14-12-52

Bildschirmfoto vom 2023-03-23 14-13-05

textual diagnose

Textual Diagnostics

Versions

Name Value
Textual 0.15.1
Rich 13.3.2

Python

Name Value
Version 3.8.12
Implementation CPython
Compiler GCC 11.2.0
Executable /home/xxx/.virtualenvs/insole3_py_3_8/bin/python

Operating System

Name Value
System Linux
Release 5.19.0-35-generic
Version #36-Ubuntu SMP PREEMPT_DYNAMIC Fri Feb 3 18:36:56 UTC 2023

Terminal

Name Value
Terminal Application Unknown
TERM xterm-256color
COLORTERM truecolor
FORCE_COLOR Not set
NO_COLOR Not set

Rich Console options

Name Value
size width=80, height=24
legacy_windows False
min_width 1
max_width 80
is_terminal True
encoding utf-8
max_height 24
justify None
overflow None
no_wrap False
highlight None
markup None
height None
@github-actions
Copy link

We found the following entries in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

The lack of Console Markup was an attempt to speed up rendering. We may be able reenable that, or at least make it an option.

@willmcgugan
Copy link
Collaborator

Fixed in #2122

@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants