Skip to content

Commit e2f63c6

Browse files
committed
rich load auto width
1 parent 8370394 commit e2f63c6

File tree

3 files changed

+203
-0
lines changed

3 files changed

+203
-0
lines changed

src/textual/widgets/_rich_log.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ def on_resize(self, event: Resize) -> None:
138138
deferred_render = deferred_renders.popleft()
139139
self.write(*deferred_render)
140140

141+
def get_content_width(self, container: Size, viewport: Size) -> int:
142+
if self._size_known:
143+
return self.virtual_size.width
144+
else:
145+
return container.width
146+
141147
def _make_renderable(self, content: RenderableType | object) -> RenderableType:
142148
"""Make content renderable.
143149
Lines changed: 153 additions & 0 deletions
Loading

tests/snapshot_tests/test_snapshots.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,3 +3582,47 @@ async def run_before(pilot: Pilot) -> None:
35823582
await pilot.pause()
35833583

35843584
assert snap_compare(TooltipApp(), run_before=run_before)
3585+
3586+
3587+
def test_auto_rich_log_width(snap_compare):
3588+
"""Regression test for https://github.com/Textualize/textual/issues/5472
3589+
3590+
You should see a tabbed content with a single line of text in the middle of the page.
3591+
3592+
"""
3593+
3594+
class MinimalApp(App):
3595+
"""A minimal Textual app demonstrating the RichLog border issue."""
3596+
3597+
CSS = """
3598+
TabbedContent {
3599+
height: 100%;
3600+
}
3601+
3602+
#title-container {
3603+
align: center middle;
3604+
}
3605+
3606+
#title-rich-log {
3607+
overflow-y: auto;
3608+
background: black 0%;
3609+
background: blue;
3610+
width: auto;
3611+
height: auto;
3612+
/* When removing the border, the whole thing is gone? */
3613+
# border: solid green 0%;
3614+
}
3615+
"""
3616+
3617+
def compose(self) -> ComposeResult:
3618+
"""Create child widgets for the app."""
3619+
with TabbedContent():
3620+
with TabPane("Title Slide", id="title-slide-tab"):
3621+
yield Container(RichLog(id="title-rich-log"), id="title-container")
3622+
3623+
def on_mount(self) -> None:
3624+
"""Add some text to the RichLogs."""
3625+
title_rich_log = self.query_one("#title-rich-log", RichLog)
3626+
title_rich_log.write("This is the Title Slide RichLog")
3627+
3628+
assert snap_compare(MinimalApp())

0 commit comments

Comments
 (0)