Skip to content

Commit 67fcbde

Browse files
authored
Merge branch 'main' into footer-fix
2 parents 41e2b71 + b274894 commit 67fcbde

File tree

6 files changed

+190
-98
lines changed

6 files changed

+190
-98
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
- Fixed fr units for horizontal and vertical layouts https://github.com/Textualize/textual/pull/1067
1414
- Fixed `textual run` breaking sys.argv https://github.com/Textualize/textual/issues/1064
1515
- Fixed footer not updating styles when toggling dark mode
16+
- Fixed how the app title in a `Header` is centred https://github.com/Textualize/textual/issues/1060
17+
- Fixed the swapping of button variants https://github.com/Textualize/textual/issues/1048
18+
- Fixed reserved characters in screenshots https://github.com/Textualize/textual/issues/993
1619

1720
### Changed
1821

1922
- DOMQuery now raises InvalidQueryFormat in response to invalid query strings, rather than cryptic CSS error
2023
- Dropped quit_after, screenshot, and screenshot_title from App.run, which can all be done via auto_pilot
2124
- Widgets are now closed in reversed DOM order
25+
- Changed `textual run` so that it patches `argv` in more situations
2226

2327
### Added
2428

sandbox/will/fr.py

Lines changed: 0 additions & 96 deletions
This file was deleted.

src/textual/widgets/_text_log.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(
4646
) -> None:
4747
super().__init__(name=name, id=id, classes=classes)
4848
self.max_lines = max_lines
49+
self._start_line: int = 0
4950
self.lines: list[list[Segment]] = []
5051
self._line_cache: LRUCache[tuple[int, int, int, int], list[Segment]]
5152
self._line_cache = LRUCache(1024)
@@ -95,16 +96,20 @@ def write(self, content: RenderableType | object) -> None:
9596
)
9697
self.lines.extend(lines)
9798

98-
if self.max_lines is not None:
99+
if self.max_lines is not None and len(self.lines) > self.max_lines:
100+
self._start_line += len(self.lines) - self.max_lines
101+
self.refresh()
99102
self.lines = self.lines[-self.max_lines :]
100103
self.virtual_size = Size(self.max_width, len(self.lines))
101104
self.scroll_end(animate=False, speed=100)
102105

103106
def clear(self) -> None:
104107
"""Clear the text log."""
105108
del self.lines[:]
109+
self._start_line = 0
106110
self.max_width = 0
107111
self.virtual_size = Size(self.max_width, len(self.lines))
112+
self.refresh()
108113

109114
def render_line(self, y: int) -> list[Segment]:
110115
scroll_x, scroll_y = self.scroll_offset
@@ -129,7 +134,7 @@ def _render_line(self, y: int, scroll_x: int, width: int) -> list[Segment]:
129134
if y >= len(self.lines):
130135
return [Segment(" " * width, self.rich_style)]
131136

132-
key = (y, scroll_x, width, self.max_width)
137+
key = (y + self._start_line, scroll_x, width, self.max_width)
133138
if key in self._line_cache:
134139
return self._line_cache[key]
135140

tests/snapshot_tests/__snapshots__/test_snapshots.ambr

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6165,6 +6165,161 @@
61656165

61666166
'''
61676167
# ---
6168+
# name: test_textlog_max_lines
6169+
'''
6170+
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">
6171+
<!-- Generated with Rich https://www.textualize.io -->
6172+
<style>
6173+
6174+
@font-face {
6175+
font-family: "Fira Code";
6176+
src: local("FiraCode-Regular"),
6177+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),
6178+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");
6179+
font-style: normal;
6180+
font-weight: 400;
6181+
}
6182+
@font-face {
6183+
font-family: "Fira Code";
6184+
src: local("FiraCode-Bold"),
6185+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),
6186+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");
6187+
font-style: bold;
6188+
font-weight: 700;
6189+
}
6190+
6191+
.terminal-2820474000-matrix {
6192+
font-family: Fira Code, monospace;
6193+
font-size: 20px;
6194+
line-height: 24.4px;
6195+
font-variant-east-asian: full-width;
6196+
}
6197+
6198+
.terminal-2820474000-title {
6199+
font-size: 18px;
6200+
font-weight: bold;
6201+
font-family: arial;
6202+
}
6203+
6204+
.terminal-2820474000-r1 { fill: #e1e1e1 }
6205+
.terminal-2820474000-r2 { fill: #c5c8c6 }
6206+
</style>
6207+
6208+
<defs>
6209+
<clipPath id="terminal-2820474000-clip-terminal">
6210+
<rect x="0" y="0" width="975.0" height="584.5999999999999" />
6211+
</clipPath>
6212+
<clipPath id="terminal-2820474000-line-0">
6213+
<rect x="0" y="1.5" width="976" height="24.65"/>
6214+
</clipPath>
6215+
<clipPath id="terminal-2820474000-line-1">
6216+
<rect x="0" y="25.9" width="976" height="24.65"/>
6217+
</clipPath>
6218+
<clipPath id="terminal-2820474000-line-2">
6219+
<rect x="0" y="50.3" width="976" height="24.65"/>
6220+
</clipPath>
6221+
<clipPath id="terminal-2820474000-line-3">
6222+
<rect x="0" y="74.7" width="976" height="24.65"/>
6223+
</clipPath>
6224+
<clipPath id="terminal-2820474000-line-4">
6225+
<rect x="0" y="99.1" width="976" height="24.65"/>
6226+
</clipPath>
6227+
<clipPath id="terminal-2820474000-line-5">
6228+
<rect x="0" y="123.5" width="976" height="24.65"/>
6229+
</clipPath>
6230+
<clipPath id="terminal-2820474000-line-6">
6231+
<rect x="0" y="147.9" width="976" height="24.65"/>
6232+
</clipPath>
6233+
<clipPath id="terminal-2820474000-line-7">
6234+
<rect x="0" y="172.3" width="976" height="24.65"/>
6235+
</clipPath>
6236+
<clipPath id="terminal-2820474000-line-8">
6237+
<rect x="0" y="196.7" width="976" height="24.65"/>
6238+
</clipPath>
6239+
<clipPath id="terminal-2820474000-line-9">
6240+
<rect x="0" y="221.1" width="976" height="24.65"/>
6241+
</clipPath>
6242+
<clipPath id="terminal-2820474000-line-10">
6243+
<rect x="0" y="245.5" width="976" height="24.65"/>
6244+
</clipPath>
6245+
<clipPath id="terminal-2820474000-line-11">
6246+
<rect x="0" y="269.9" width="976" height="24.65"/>
6247+
</clipPath>
6248+
<clipPath id="terminal-2820474000-line-12">
6249+
<rect x="0" y="294.3" width="976" height="24.65"/>
6250+
</clipPath>
6251+
<clipPath id="terminal-2820474000-line-13">
6252+
<rect x="0" y="318.7" width="976" height="24.65"/>
6253+
</clipPath>
6254+
<clipPath id="terminal-2820474000-line-14">
6255+
<rect x="0" y="343.1" width="976" height="24.65"/>
6256+
</clipPath>
6257+
<clipPath id="terminal-2820474000-line-15">
6258+
<rect x="0" y="367.5" width="976" height="24.65"/>
6259+
</clipPath>
6260+
<clipPath id="terminal-2820474000-line-16">
6261+
<rect x="0" y="391.9" width="976" height="24.65"/>
6262+
</clipPath>
6263+
<clipPath id="terminal-2820474000-line-17">
6264+
<rect x="0" y="416.3" width="976" height="24.65"/>
6265+
</clipPath>
6266+
<clipPath id="terminal-2820474000-line-18">
6267+
<rect x="0" y="440.7" width="976" height="24.65"/>
6268+
</clipPath>
6269+
<clipPath id="terminal-2820474000-line-19">
6270+
<rect x="0" y="465.1" width="976" height="24.65"/>
6271+
</clipPath>
6272+
<clipPath id="terminal-2820474000-line-20">
6273+
<rect x="0" y="489.5" width="976" height="24.65"/>
6274+
</clipPath>
6275+
<clipPath id="terminal-2820474000-line-21">
6276+
<rect x="0" y="513.9" width="976" height="24.65"/>
6277+
</clipPath>
6278+
<clipPath id="terminal-2820474000-line-22">
6279+
<rect x="0" y="538.3" width="976" height="24.65"/>
6280+
</clipPath>
6281+
</defs>
6282+
6283+
<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-2820474000-title" fill="#c5c8c6" text-anchor="middle" x="496" y="27">TextLogLines</text>
6284+
<g transform="translate(26,22)">
6285+
<circle cx="0" cy="0" r="7" fill="#ff5f57"/>
6286+
<circle cx="22" cy="0" r="7" fill="#febc2e"/>
6287+
<circle cx="44" cy="0" r="7" fill="#28c840"/>
6288+
</g>
6289+
6290+
<g transform="translate(9, 41)" clip-path="url(#terminal-2820474000-clip-terminal)">
6291+
<rect fill="#1e1e1e" x="0" y="1.5" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="1.5" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="25.9" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="25.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="50.3" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="50.3" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="74.7" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="74.7" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="99.1" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="99.1" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="123.5" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="123.5" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="147.9" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="147.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="172.3" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="172.3" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="196.7" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="196.7" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="221.1" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="221.1" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="245.5" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="245.5" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="269.9" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="269.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="294.3" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="294.3" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="318.7" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="318.7" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="343.1" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="343.1" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="367.5" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="367.5" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="391.9" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="391.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="416.3" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="416.3" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="440.7" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="440.7" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="465.1" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="465.1" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="489.5" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="489.5" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="513.9" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="513.9" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="538.3" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="538.3" width="24.4" height="24.65" shape-rendering="crispEdges"/><rect fill="#1e1e1e" x="0" y="562.7" width="951.6" height="24.65" shape-rendering="crispEdges"/><rect fill="#14191f" x="951.6" y="562.7" width="24.4" height="24.65" shape-rendering="crispEdges"/>
6292+
<g class="terminal-2820474000-matrix">
6293+
<text class="terminal-2820474000-r1" x="0" y="20" textLength="951.6" clip-path="url(#terminal-2820474000-line-0)">Key&#160;press&#160;#3&#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;&#160;</text><text class="terminal-2820474000-r2" x="976" y="20" textLength="12.2" clip-path="url(#terminal-2820474000-line-0)">
6294+
</text><text class="terminal-2820474000-r1" x="0" y="44.4" textLength="951.6" clip-path="url(#terminal-2820474000-line-1)">Key&#160;press&#160;#4&#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;&#160;</text><text class="terminal-2820474000-r2" x="976" y="44.4" textLength="12.2" clip-path="url(#terminal-2820474000-line-1)">
6295+
</text><text class="terminal-2820474000-r1" x="0" y="68.8" textLength="951.6" clip-path="url(#terminal-2820474000-line-2)">Key&#160;press&#160;#5&#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;&#160;</text><text class="terminal-2820474000-r2" x="976" y="68.8" textLength="12.2" clip-path="url(#terminal-2820474000-line-2)">
6296+
</text><text class="terminal-2820474000-r2" x="976" y="93.2" textLength="12.2" clip-path="url(#terminal-2820474000-line-3)">
6297+
</text><text class="terminal-2820474000-r2" x="976" y="117.6" textLength="12.2" clip-path="url(#terminal-2820474000-line-4)">
6298+
</text><text class="terminal-2820474000-r2" x="976" y="142" textLength="12.2" clip-path="url(#terminal-2820474000-line-5)">
6299+
</text><text class="terminal-2820474000-r2" x="976" y="166.4" textLength="12.2" clip-path="url(#terminal-2820474000-line-6)">
6300+
</text><text class="terminal-2820474000-r2" x="976" y="190.8" textLength="12.2" clip-path="url(#terminal-2820474000-line-7)">
6301+
</text><text class="terminal-2820474000-r2" x="976" y="215.2" textLength="12.2" clip-path="url(#terminal-2820474000-line-8)">
6302+
</text><text class="terminal-2820474000-r2" x="976" y="239.6" textLength="12.2" clip-path="url(#terminal-2820474000-line-9)">
6303+
</text><text class="terminal-2820474000-r2" x="976" y="264" textLength="12.2" clip-path="url(#terminal-2820474000-line-10)">
6304+
</text><text class="terminal-2820474000-r2" x="976" y="288.4" textLength="12.2" clip-path="url(#terminal-2820474000-line-11)">
6305+
</text><text class="terminal-2820474000-r2" x="976" y="312.8" textLength="12.2" clip-path="url(#terminal-2820474000-line-12)">
6306+
</text><text class="terminal-2820474000-r2" x="976" y="337.2" textLength="12.2" clip-path="url(#terminal-2820474000-line-13)">
6307+
</text><text class="terminal-2820474000-r2" x="976" y="361.6" textLength="12.2" clip-path="url(#terminal-2820474000-line-14)">
6308+
</text><text class="terminal-2820474000-r2" x="976" y="386" textLength="12.2" clip-path="url(#terminal-2820474000-line-15)">
6309+
</text><text class="terminal-2820474000-r2" x="976" y="410.4" textLength="12.2" clip-path="url(#terminal-2820474000-line-16)">
6310+
</text><text class="terminal-2820474000-r2" x="976" y="434.8" textLength="12.2" clip-path="url(#terminal-2820474000-line-17)">
6311+
</text><text class="terminal-2820474000-r2" x="976" y="459.2" textLength="12.2" clip-path="url(#terminal-2820474000-line-18)">
6312+
</text><text class="terminal-2820474000-r2" x="976" y="483.6" textLength="12.2" clip-path="url(#terminal-2820474000-line-19)">
6313+
</text><text class="terminal-2820474000-r2" x="976" y="508" textLength="12.2" clip-path="url(#terminal-2820474000-line-20)">
6314+
</text><text class="terminal-2820474000-r2" x="976" y="532.4" textLength="12.2" clip-path="url(#terminal-2820474000-line-21)">
6315+
</text><text class="terminal-2820474000-r2" x="976" y="556.8" textLength="12.2" clip-path="url(#terminal-2820474000-line-22)">
6316+
</text>
6317+
</g>
6318+
</g>
6319+
</svg>
6320+
6321+
'''
6322+
# ---
61686323
# name: test_vertical_layout
61696324
'''
61706325
<svg class="rich-terminal" viewBox="0 0 994 635.5999999999999" xmlns="http://www.w3.org/2000/svg">

tests/snapshot_tests/test_snapshots.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def test_header_render(snap_compare):
8585
assert snap_compare("docs/examples/widgets/header.py")
8686

8787

88+
def test_textlog_max_lines(snap_compare):
89+
assert snap_compare("tests/snapshots/textlog_max_lines.py", press=[*"abcde", "_"])
90+
91+
8892
def test_fr_units(snap_compare):
8993
assert snap_compare("tests/snapshots/fr_units.py")
9094

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from textual.app import App
2+
from textual.widgets import TextLog
3+
4+
5+
class TextLogLines(App):
6+
count = 0
7+
8+
def compose(self):
9+
yield TextLog(max_lines=3)
10+
11+
async def on_key(self):
12+
self.count += 1
13+
log_widget = self.query_one(TextLog)
14+
log_widget.write(f"Key press #{self.count}")
15+
16+
17+
app = TextLogLines()
18+
19+
if __name__ == "__main__":
20+
app.run()

0 commit comments

Comments
 (0)