-
Notifications
You must be signed in to change notification settings - Fork 815
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
Width of Static is miscalulated when markup is used #4447
Comments
What version of Textual are you using? I seem to remember this issue (or something like it) was fixed a few months back. |
Version info:
|
Thanks, could you possibly provide a minimal reproducible example (MRE): i.e. a short piece of code that can reproduce the issue? |
Here you go: from rich.style import Style
from textual.app import App, ComposeResult
from textual.widgets import Static
class BorkedApp(App):
"""The main application class for the Songbook TUI."""
text = "Hello, world!"
style = Style(bgcolor="#333333", bold=True)
text_styled = style.render(text)
CSS_PATH = "app.tcss"
DEFAULT_CSS = """
Static {
width: auto;
border: round green;
}
"""
BINDINGS = [("q", "exit", "Quit")]
def compose(self) -> ComposeResult:
"""Compose the main application."""
yield Static(self.text)
yield Static(self.text_styled)
if __name__ == "__main__":
app = BorkedApp()
app.run() Result: |
This also causes some weird see-through issues with the screen below btw. I can solve that by adding another entire black screen behind, it's just inconvenient, but I might open up a separate ticket for that. |
styled_text = "[green bold]Hello World[/]" |
You are right, this works well. Styling with |
Don't forget to star the repository! Follow @textualizeio for Textual updates. |
@valentingregoire You can style with Style objects e.g. |
When adding markup to a text in a
Static
(markup=True
), then the width of the text is based on the content with the style characters.Example without markup:
Example with markup:
I think the width is calculated by the amount of characters (columns) before parsing. Perhaps if
markup=True
, the width can be calculated after parsing?The text was updated successfully, but these errors were encountered: