Skip to content

Commit b38b9fc

Browse files
committed
snapshots
1 parent 458a8e5 commit b38b9fc

File tree

360 files changed

+22681
-22665
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

360 files changed

+22681
-22665
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Footer can now be scrolled horizontally without holding `shift` https://github.com/Textualize/textual/pull/5404
1313
- The content of an `Input` will now only be automatically selected when the widget is focused by the user, not when the app itself has regained focus (similar to web browsers). https://github.com/Textualize/textual/pull/5379
14+
- Meta is now discarded in snapshot tests, which should make snapshots less likely to fail without any visible differences
1415

1516
### Added
1617

src/textual/_compositor.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,9 @@ def render_full_update(self, simplify: bool = False) -> LayoutUpdate:
11141114
crop = screen_region
11151115
chops = self._render_chops(crop, lambda y: True)
11161116
if simplify:
1117-
render_strips = [Strip.join(chop.values()).simplify() for chop in chops]
1117+
render_strips = [
1118+
Strip.join(chop.values()).discard_meta().simplify() for chop in chops
1119+
]
11181120
else:
11191121
render_strips = [Strip.join(chop.values()) for chop in chops]
11201122

src/textual/_styles_cache.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from rich.console import Console
88
from rich.segment import Segment
99
from rich.style import Style
10+
from rich.terminal_theme import TerminalTheme
1011
from rich.text import Text
1112

1213
from textual import log
@@ -144,6 +145,7 @@ def render_widget(self, widget: Widget, crop: Region) -> list[Strip]:
144145
crop=crop,
145146
filters=widget.app._filters,
146147
opacity=widget.opacity,
148+
ansi_theme=widget.app.ansi_theme,
147149
)
148150
if widget.auto_links:
149151
hover_style = widget.hover_style
@@ -176,6 +178,7 @@ def render(
176178
crop: Region | None = None,
177179
filters: Sequence[LineFilter] | None = None,
178180
opacity: float = 1.0,
181+
ansi_theme: TerminalTheme = DEFAULT_TERMINAL_THEME,
179182
) -> list[Strip]:
180183
"""Render a widget content plus CSS styles.
181184
@@ -231,6 +234,7 @@ def render(
231234
border_title,
232235
border_subtitle,
233236
opacity,
237+
ansi_theme,
234238
)
235239
self._cache[y] = strip
236240
else:
@@ -267,6 +271,7 @@ def render_line(
267271
border_title: tuple[Text, Color, Color, Style] | None,
268272
border_subtitle: tuple[Text, Color, Color, Style] | None,
269273
opacity: float,
274+
ansi_theme: TerminalTheme,
270275
) -> Strip:
271276
"""Render a styled line.
272277
@@ -447,7 +452,9 @@ def post(segments: Iterable[Segment]) -> Iterable[Segment]:
447452
if inner:
448453
line = Segment.apply_style(line, inner)
449454
if styles.text_opacity != 1.0:
450-
line = TextOpacity.process_segments(line, styles.text_opacity)
455+
line = TextOpacity.process_segments(
456+
line, styles.text_opacity, ansi_theme
457+
)
451458
line = line_post(line_pad(line, pad_left, pad_right, inner))
452459

453460
if border_left or border_right:

src/textual/content.py

-10
Original file line numberDiff line numberDiff line change
@@ -1024,17 +1024,11 @@ def __init__(
10241024
self.align = align
10251025
self.line_end = line_end
10261026
self.link_style = link_style
1027-
self.highlight_style: Style | None = None
1028-
self.highlight_range: tuple[int | None, int | None] | None = None
10291027

10301028
@property
10311029
def plain(self) -> str:
10321030
return self.content.plain
10331031

1034-
def highlight(self, style: Style, start: int | None, end: int | None) -> None:
1035-
self.highlight_style = style
1036-
self.highlight_range = (start, end)
1037-
10381032
def to_strip(self, widget: Widget, style: Style) -> Strip:
10391033
_Segment = Segment
10401034
align = self.align
@@ -1044,10 +1038,6 @@ def to_strip(self, widget: Widget, style: Style) -> Strip:
10441038
x = self.x
10451039
y = self.y
10461040

1047-
if self.highlight_style is not None and self.highlight_range is not None:
1048-
start, end = self.highlight_range
1049-
content = content.stylize(self.highlight_style, start, end)
1050-
10511041
if align in ("start", "left") or (align == "justify" and self.line_end):
10521042
pass
10531043

src/textual/renderables/text_opacity.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
from rich.console import Console, ConsoleOptions, RenderableType, RenderResult
77
from rich.segment import Segment
88
from rich.style import Style
9+
from rich.terminal_theme import TerminalTheme
910

11+
from textual._ansi_theme import DEFAULT_TERMINAL_THEME
12+
from textual._context import active_app
13+
from textual.color import TRANSPARENT
14+
from textual.filter import ANSIToTruecolor
1015
from textual.renderables._blend_colors import blend_colors
1116

1217

@@ -47,13 +52,14 @@ def __init__(self, renderable: RenderableType, opacity: float = 1.0) -> None:
4752

4853
@classmethod
4954
def process_segments(
50-
cls, segments: Iterable[Segment], opacity: float
55+
cls, segments: Iterable[Segment], opacity: float, ansi_theme: TerminalTheme
5156
) -> Iterable[Segment]:
5257
"""Apply opacity to segments.
5358
5459
Args:
5560
segments: Incoming segments.
5661
opacity: Opacity to apply.
62+
ansi_theme: Terminal theme.
5763
5864
Returns:
5965
Segments with applied opacity.
@@ -70,7 +76,8 @@ def process_segments(
7076
invisible_style = _from_color(bgcolor=style.bgcolor)
7177
yield _Segment(cell_len(text) * " ", invisible_style)
7278
else:
73-
for segment in segments:
79+
filter = ANSIToTruecolor(ansi_theme)
80+
for segment in filter.apply(list(segments), TRANSPARENT):
7481
# use Tuple rather than tuple so Python 3.7 doesn't complain
7582
text, style, control = cast(Tuple[str, Style, object], segment)
7683
if not style:
@@ -88,5 +95,11 @@ def process_segments(
8895
def __rich_console__(
8996
self, console: Console, options: ConsoleOptions
9097
) -> RenderResult:
98+
try:
99+
app = active_app.get()
100+
except LookupError:
101+
ansi_theme = DEFAULT_TERMINAL_THEME
102+
else:
103+
ansi_theme = app.ansi_theme
91104
segments = console.render(self.renderable, options)
92-
return self.process_segments(segments, self.opacity)
105+
return self.process_segments(segments, self.opacity, ansi_theme)

src/textual/screen.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,11 @@ def _forward_event(self, event: events.Event) -> None:
14891489
select_widget, select_offset = self.get_widget_and_offset_at(
14901490
event.x, event.y
14911491
)
1492-
if self._select_end is not None and select_offset is None:
1492+
if (
1493+
self._select_end is not None
1494+
and select_offset is None
1495+
and event.y > self._select_end[1].y
1496+
):
14931497
end_widget = self._select_end[0]
14941498
select_offset = end_widget.content_region.bottom_right_inclusive
14951499
self._select_end = (end_widget, event.offset, select_offset)

src/textual/widget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,7 @@ def link_style(self) -> Style:
22902290
)
22912291
style = styles.link_style + Style.from_color(
22922292
link_color.rich_color,
2293-
link_background.rich_color,
2293+
link_background.rich_color if styles.link_background.a else None,
22942294
)
22952295
return style
22962296

tests/renderables/test_text_opacity.py

-7
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ def test_text_opacity_value_of_one_noop(text):
2929
assert render(TextOpacity(text, opacity=1)) == render(text)
3030

3131

32-
def test_ansi_colors_noop():
33-
ansi_colored_text = Text("Hello, world!", style="red on green", end="")
34-
assert render(TextOpacity(ansi_colored_text, opacity=0.5)) == render(
35-
ansi_colored_text
36-
)
37-
38-
3932
def test_text_opacity_no_style_noop():
4033
text_no_style = Text("Hello, world!", end="")
4134
assert render(TextOpacity(text_no_style, opacity=0.2)) == render(text_no_style)

0 commit comments

Comments
 (0)