Incorrect word wrapping in horizontal layout #3325
-
I'm seeing an issue with word-wrapping if a Notice how the text is properly wrapped without the timestamp widget and how parts of the text seem to continue outside of the terminal with the timestamp. I've installed textual and rich from git: $ pip install --upgrade --force git+https://github.com/textualize/textual/
$ pip install --upgrade --force git+https://github.com/textualize/rich/ import textual.app
import textual.containers
import textual.widget
import textual.widgets
TEXT = (
"So many resources are devoted to internal issues that no external input "
"can be processed anymore, and the system stops working. The world may be "
"undergoing a revolution, Rome may be burning, but the philosophical "
"discourse remains detached, meaningless, and utterly oblivious. Time for "
"an upgrade."
)
class Timestamp(textual.widgets.Static):
def __init__(self):
super().__init__('12:46:29')
self.styles.width = 'auto'
self.styles.background = 'darkgreen'
class Message(textual.widgets.Static):
def __init__(self, message):
super().__init__(message)
self.styles.background = 'navy'
class TextWrapDemo(textual.app.App):
def compose(self):
yield Message(TEXT)
yield textual.containers.Horizontal(
Timestamp(),
Message(TEXT),
)
app = TextWrapDemo()
app.run() Output of Textual DiagnosticsVersions
Python
Operating System
Terminal
Rich Console options
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Your message is being clipped. Static will use the width of the container by default. If you add on the width of your timestamp, then the message will be pushed off the right of the screen. If you set the width to "1fr", it will tell Textual to use the remaining width. import textual.app
import textual.containers
import textual.widget
import textual.widgets
TEXT = (
"So many resources are devoted to internal issues that no external input "
"can be processed anymore, and the system stops working. The world may be "
"undergoing a revolution, Rome may be burning, but the philosophical "
"discourse remains detached, meaningless, and utterly oblivious. Time for "
"an upgrade."
)
class Timestamp(textual.widgets.Static):
def __init__(self):
super().__init__("12:46:29")
self.styles.width = "auto"
self.styles.background = "darkgreen"
class Message(textual.widgets.Static):
def __init__(self, message):
super().__init__(message)
self.styles.background = "navy"
self.styles.width = "1fr"
class TextWrapDemo(textual.app.App):
def compose(self):
yield Message(TEXT)
yield textual.containers.Horizontal(
Timestamp(),
Message(TEXT),
)
app = TextWrapDemo()
app.run() If you see clipping like this. The best way to figure it out is to add a border. If the border is offscreen, then it means there is not enough space to fit all your widgets. Here's your code with a border around the message, which makes it clear what is happening: import textual.app
import textual.containers
import textual.widget
import textual.widgets
TEXT = (
"So many resources are devoted to internal issues that no external input "
"can be processed anymore, and the system stops working. The world may be "
"undergoing a revolution, Rome may be burning, but the philosophical "
"discourse remains detached, meaningless, and utterly oblivious. Time for "
"an upgrade."
)
class Timestamp(textual.widgets.Static):
def __init__(self):
super().__init__("12:46:29")
self.styles.width = "auto"
self.styles.background = "darkgreen"
class Message(textual.widgets.Static):
def __init__(self, message):
super().__init__(message)
self.styles.background = "navy"
self.styles.border = ("heavy", "green")
class TextWrapDemo(textual.app.App):
def compose(self):
yield Message(TEXT)
yield textual.containers.Horizontal(
Timestamp(),
Message(TEXT),
)
app = TextWrapDemo()
app.run() |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the quick and very helpful reply. This is highly unintuitive to me. I would expect any widget to use the space that is available, not the space of the terminal or some parent container. I guess I have to get more experience with textual and rich. |
Beta Was this translation helpful? Give feedback.
-
OK, if I you put it that way, that makes sense.
Thanks again!
|
Beta Was this translation helpful? Give feedback.
Your message is being clipped. Static will use the width of the container by default. If you add on the width of your timestamp, then the message will be pushed off the right of the screen.
If you set the width to "1fr", it will tell Textual to use the remaining width.