Merge pull request #6141 from Textualize/fix-rich-log-write

fix for setting the theme early
This commit is contained in:
Will McGugan
2025-09-29 17:23:37 +01:00
committed by GitHub
4 changed files with 176 additions and 2 deletions

View File

@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed issue where Segments with a style of `None` aren't rendered https://github.com/Textualize/textual/pull/6109 - Fixed issue where Segments with a style of `None` aren't rendered https://github.com/Textualize/textual/pull/6109
- Fixed visual glitches and crash when changing `DataTable.header_height` https://github.com/Textualize/textual/pull/6128 - Fixed visual glitches and crash when changing `DataTable.header_height` https://github.com/Textualize/textual/pull/6128
- Fixed TextArea.placeholder not handling multi-lines https://github.com/Textualize/textual/pull/6138 - Fixed TextArea.placeholder not handling multi-lines https://github.com/Textualize/textual/pull/6138
- Fixed issue with RichLog when App.theme is set early https://github.com/Textualize/textual/pull/6141
## [6.1.0] - 2025-08-01 ## [6.1.0] - 2025-08-01

View File

@@ -3657,8 +3657,9 @@ class App(Generic[ReturnType], DOMNode):
stylesheet.reparse() stylesheet.reparse()
stylesheet.update(self.app, animate=animate) stylesheet.update(self.app, animate=animate)
try: try:
self.screen._refresh_layout(self.size) if self.screen.is_mounted:
self.screen._css_update_count = self._css_update_count self.screen._refresh_layout(self.size)
self.screen._css_update_count = self._css_update_count
except ScreenError: except ScreenError:
pass pass
# The other screens in the stack will need to know about some style # The other screens in the stack will need to know about some style

View File

@@ -0,0 +1,150 @@
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
<!-- Generated with Rich https://www.textualize.io -->
<style>
@font-face {
font-family: "Fira Code";
src: local("FiraCode-Regular"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");
font-style: normal;
font-weight: 400;
}
@font-face {
font-family: "Fira Code";
src: local("FiraCode-Bold"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");
font-style: bold;
font-weight: 700;
}
.terminal-matrix {
font-family: Fira Code, monospace;
font-size: 20px;
line-height: 24.4px;
font-variant-east-asian: full-width;
}
.terminal-title {
font-size: 18px;
font-weight: bold;
font-family: arial;
}
.terminal-r1 { fill: #d8dee9 }
.terminal-r2 { fill: #c5c8c6 }
</style>
<defs>
<clipPath id="terminal-clip-terminal">
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
</clipPath>
<clipPath id="terminal-line-0">
<rect x="0" y="1.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-1">
<rect x="0" y="25.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-2">
<rect x="0" y="50.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-3">
<rect x="0" y="74.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-4">
<rect x="0" y="99.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-5">
<rect x="0" y="123.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-6">
<rect x="0" y="147.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-7">
<rect x="0" y="172.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-8">
<rect x="0" y="196.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-9">
<rect x="0" y="221.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-10">
<rect x="0" y="245.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-11">
<rect x="0" y="269.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-12">
<rect x="0" y="294.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-13">
<rect x="0" y="318.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-14">
<rect x="0" y="343.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-15">
<rect x="0" y="367.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-16">
<rect x="0" y="391.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-17">
<rect x="0" y="416.3" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-18">
<rect x="0" y="440.7" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-19">
<rect x="0" y="465.1" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-20">
<rect x="0" y="489.5" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-21">
<rect x="0" y="513.9" width="976" height="24.65"/>
</clipPath>
<clipPath id="terminal-line-22">
<rect x="0" y="538.3" width="976" height="24.65"/>
</clipPath>
</defs>
<rect fill="#292929" stroke="rgba(255,255,255,0.35)" stroke-width="1" x="1" y="1" width="992" height="633.6" rx="8"/><text class="terminal-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">TestApp</text>
<g transform="translate(26,22)">
<circle cx="0" cy="0" r="7" fill="#ff5f57"/>
<circle cx="22" cy="0" r="7" fill="#febc2e"/>
<circle cx="44" cy="0" r="7" fill="#28c840"/>
</g>
<g transform="translate(9, 41)" clip-path="url(#terminal-clip-terminal)">
<rect fill="#424959" x="0" y="1.5" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="1.5" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="25.9" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="25.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="50.3" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="50.3" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="74.7" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="74.7" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="99.1" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="99.1" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="123.5" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="123.5" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="147.9" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="147.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="172.3" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="172.3" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="196.7" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="196.7" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="221.1" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="221.1" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="245.5" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="245.5" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="269.9" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="269.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="294.3" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="294.3" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="318.7" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="318.7" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="343.1" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="343.1" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="367.5" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="367.5" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="391.9" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="391.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="416.3" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="416.3" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="440.7" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="440.7" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="465.1" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="465.1" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="489.5" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="489.5" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="513.9" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="513.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="538.3" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="538.3" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#424959" x="0" y="562.7" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e242f" x="951.6" y="562.7" width="24.4" height="24.65" shape-rendering="crispEdges"/>
<g class="terminal-matrix">
<text class="terminal-r1" x="0" y="20" textLength="951.6" clip-path="url(#terminal-line-0)">Hello,&#160;World!&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</text><text class="terminal-r2" x="976" y="20" textLength="12.2" clip-path="url(#terminal-line-0)">
</text><text class="terminal-r2" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-line-1)">
</text><text class="terminal-r2" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-line-2)">
</text><text class="terminal-r2" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-line-3)">
</text><text class="terminal-r2" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-line-4)">
</text><text class="terminal-r2" x="976" y="142" textLength="12.2" clip-path="url(#terminal-line-5)">
</text><text class="terminal-r2" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-line-6)">
</text><text class="terminal-r2" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-line-7)">
</text><text class="terminal-r2" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-line-8)">
</text><text class="terminal-r2" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-line-9)">
</text><text class="terminal-r2" x="976" y="264" textLength="12.2" clip-path="url(#terminal-line-10)">
</text><text class="terminal-r2" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-line-11)">
</text><text class="terminal-r2" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-line-12)">
</text><text class="terminal-r2" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-line-13)">
</text><text class="terminal-r2" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-line-14)">
</text><text class="terminal-r2" x="976" y="386" textLength="12.2" clip-path="url(#terminal-line-15)">
</text><text class="terminal-r2" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-line-16)">
</text><text class="terminal-r2" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-line-17)">
</text><text class="terminal-r2" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-line-18)">
</text><text class="terminal-r2" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-line-19)">
</text><text class="terminal-r2" x="976" y="508" textLength="12.2" clip-path="url(#terminal-line-20)">
</text><text class="terminal-r2" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-line-21)">
</text><text class="terminal-r2" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-line-22)">
</text>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -4653,3 +4653,25 @@ Where the fear has gone there will be nothing. Only I will remain."""
yield TextArea(placeholder=TEXT) yield TextArea(placeholder=TEXT)
assert snap_compare(PlaceholderApp()) assert snap_compare(PlaceholderApp())
def test_rich_log_early_write(snap_compare) -> None:
"""Regression test for https://github.com/Textualize/textual/issues/6123
You should see a RichLog with "Hello World" text
"""
class TestApp(App):
def compose(self) -> ComposeResult:
with Horizontal():
yield RichLog()
def on_mount(self) -> None:
self.theme = "nord"
def on_ready(self) -> None:
log_widget = self.query_one(RichLog)
log_widget.write("Hello, World!")
assert snap_compare(TestApp())