You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
fromtextual.appimportApp, ComposeResultfromtextual.widgetsimportStaticfromrich.tableimportTablefromrichimportprintfromrich.textimportTextdefdo_nothing(a):
returnadefrich_table(title="", from_markup_working=True, raw=False):
t=Table()
from_markup=do_nothingifrawelseText.from_markupiffrom_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]"),
)
returntrich_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),
]
classWelcomeApp(App):
defcompose(self) ->ComposeResult:
fortinrich_tables:
yieldStatic(t)
if__name__=="__main__":
app=WelcomeApp()
app.run()
fortinrich_tables:
print(t)
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
The text was updated successfully, but these errors were encountered:
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 modifiedfrom_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?textual diagnose
Textual Diagnostics
Versions
Python
Operating System
Terminal
Rich Console options
The text was updated successfully, but these errors were encountered: