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

How to get Label widget to automatically wrap for long text? #1685

Closed
willmcgugan opened this issue Jan 28, 2023 Discussed in #1684 · 1 comment · Fixed by #1686
Closed

How to get Label widget to automatically wrap for long text? #1685

willmcgugan opened this issue Jan 28, 2023 Discussed in #1684 · 1 comment · Fixed by #1686

Comments

@willmcgugan
Copy link
Collaborator

Discussed in #1684

Originally posted by learnbyexample January 28, 2023
Here's a sample app. Static is working as expected but I'm not able to make Label to wrap long text. Also, passing output of Panel to Label wraps around but the right box border is missing. Textual version is 0.10.0

from textual.app import App
from textual.widgets import Label, Static
from rich.panel import Panel

class LabelWrap(App):
    CSS = '''Screen {
              align: center middle;
          }

          #l_data {
              border: blank;
              background: lightgray;
          }

          #s_data {
              border: blank;
              background: lightgreen;
          }

          #p_data {
              border: blank;
              background: lightgray;
          }'''

    def __init__(self):
        super().__init__()

        self.data = ('Apple Banana Cherry Mango Fig Guava Pineapple:'
                     'Dragon Unicorn Centaur Phoenix Chimera Castle')

    def compose(self):
        yield Label(self.data, id='l_data')
        yield Static(self.data, id='s_data')
        yield Label(Panel(self.data), id='p_data')

    def on_mount(self):
        self.dark = False

if __name__ == '__main__':
    app = LabelWrap()
    app.run()

Screenshot of running the above code with 72x18 terminal dimensions:
label_wrap

@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

Successfully merging a pull request may close this issue.

1 participant