-
Hey there, 🙂 First of all, let me thank you for all the work you're doing at Textualize. You guys literally changed the way I develop my small projects. Please do keep it up! Well, I was in the midst of porting a project I did with Textual 0.1.x to the newer 0.2.0 version, in which I rendered Textualize Widgets using Rich Panels. I noticed that the usual Rich text formatting isn't being recognized at all with the Panels, but does work for a regular text render as seen below. No idea what I could be doing wrong or if this is a bug, since it worked fine with 0.1.x. Here's my code: from textual.app import App, ComposeResult, RenderResult
from textual.widget import Widget
from rich.panel import Panel
class DoesntWork(Widget):
def render(self) -> RenderResult:
return Panel("Hello, [red]World[/]!")
class Works(Widget):
def render(self) -> RenderResult:
return "Hello, [red]World[/]!"
class Test(App):
CSS_PATH = "style.css"
def compose(self) -> ComposeResult:
yield DoesntWork()
yield Works()
app = Test()
app.run() I also tried doing using Here is my requirements/pip freeze if that is useful somehow, even though I did a fresh reinstall of my virtual environment minutes ago just to check: requirements.txt
Thanks you for reading this! Cheers, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Hey Posho, glad you're enjoying Textual. As you've probably guessed much has changed from 0.1.0 to 0.2.0 (and beyond) and while Rich renderables will still work (with I believe (I've only really come on board with 0.2.0) some differences to how you use them) much of what you're wanting to do here is likely better done now using the full features of CSS. So, for example, as I understand it, you want some red text inside a box? Now you could do this: from textual.app import App, RenderResult, ComposeResult
from textual.widgets import Label
class Hello( Label ):
DEFAULT_CSS = """
Hello {
border: round white;
height: 100%;
}
"""
def render(self) -> RenderResult:
return "Hello, [red]World[/]!"
class Test(App):
def compose(self) -> ComposeResult:
yield Hello()
app = Test()
app.run() Playing some more, and I don't know if this is intentional or not, it looks like you can still use a from textual.app import App, RenderResult, ComposeResult
from textual.widgets import Label
from rich.panel import Panel
from rich.text import Text
class Hello( Label ):
def render(self) -> RenderResult:
return Panel( Text.from_markup( "Hello, [red]World[/]!" ) )
class Test(App):
def compose(self) -> ComposeResult:
yield Hello()
app = Test()
app.run() I'm not so familiar with Rich and parts of Rich within Textual yet so I might be missing something here, but that seems to work. However, I think I'd be inclined to go with something more like the former as there's a lot of power to be had from using the new CSS approach. |
Beta Was this translation helpful? Give feedback.
Hey Posho, glad you're enjoying Textual. As you've probably guessed much has changed from 0.1.0 to 0.2.0 (and beyond) and while Rich renderables will still work (with I believe (I've only really come on board with 0.2.0) some differences to how you use them) much of what you're wanting to do here is likely better done now using the full features of CSS.
So, for example, as I understand it, you want some red text inside a box? Now you could do this: