Skip to content

Commit

Permalink
test fix, fix outline
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jan 18, 2025
1 parent a745cda commit b055673
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/textual/_styles_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,9 @@ def post(segments: Iterable[Segment]) -> Iterable[Segment]:

elif outline_left or outline_right:
# Lines in side outline
left_style = Style(background=(base_background + outline_left_color))
left_style = Style(foreground=(base_background + outline_left_color))
left = get_box(outline_left, inner, outer, left_style)[1][0]
right_style = Style(background=(base_background + outline_right_color))
right_style = Style(foreground=(base_background + outline_right_color))
right = get_box(outline_right, inner, outer, right_style)[1][2]
line = line_trim(list(line), outline_left != "", outline_right != "")
if outline_left and outline_right:
Expand Down
4 changes: 3 additions & 1 deletion src/textual/strip.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def __init__(
assert get_line_length(self._segments) == cell_length

def __rich_repr__(self) -> rich.repr.Result:
return
yield self._segments
yield self.cell_length

Expand Down Expand Up @@ -342,6 +341,9 @@ def adjust_cell_length(self, cell_length: int, style: Style | None = None) -> St
A new strip with the supplied cell length.
"""

if self.cell_length == cell_length:
return self

cache_key = (cell_length, style)
cached_strip = self._line_length_cache.get(cache_key)
if cached_strip is not None:
Expand Down
21 changes: 11 additions & 10 deletions tests/snapshot_tests/snapshot_apps/ansi_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
class AnsiMappingApp(App[None]):
def compose(self) -> ComposeResult:
ansi_colors = [
"red",
"green",
"yellow",
"blue",
"magenta",
"cyan",
"white",
"black",
"ansi_red",
"ansi_green",
"ansi_yellow",
"ansi_blue",
"ansi_magenta",
"ansi_cyan",
"ansi_white",
"ansi_black",
]
yield Label("Foreground & background")
for color in ansi_colors:
yield Label(f"[{color}]{color}[/]")
yield Label(f"[dim {color}]dim {color}[/]")
color_name = color.partition("_")[-1]
yield Label(f"[{color}]{color_name}[/]")
yield Label(f"[dim {color}]dim {color_name}[/]")


app = AnsiMappingApp()
Expand Down
20 changes: 13 additions & 7 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def on_mount(self) -> None:
def test_input_cursor(snap_compare):
"""The first input should say こんにちは.
The second input should say こんにちは, with a cursor on the final character (double width).
Note that this might render incorrectly in the SVG output - the letters may overlap."""
Note that this might render incorrectly in the SVG output - the letters may overlap.
"""

class InputApp(App[None]):
def compose(self) -> ComposeResult:
Expand Down Expand Up @@ -2078,7 +2079,7 @@ class ANSIApp(App):
"""

def compose(self) -> ComposeResult:
yield Label("[red]Red[/] [magenta]Magenta[/]")
yield Label("[ansi_red]Red[/] [ansi_magenta]Magenta[/]")

app = ANSIApp(ansi_color=True)
assert snap_compare(app)
Expand Down Expand Up @@ -2886,7 +2887,8 @@ async def run_before(pilot: Pilot) -> None:

def test_markup_command_list(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/5276
You should see a command list, with console markup applied to the action name and help text."""
You should see a command list, with console markup applied to the action name and help text.
"""

class MyApp(App):
def on_mount(self) -> None:
Expand Down Expand Up @@ -2945,7 +2947,8 @@ def on_resize(self) -> None:

def test_add_remove_tabs(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/5215
You should see a TabbedContent with three panes, entitled 'tab-2', 'New tab' and 'New tab'"""
You should see a TabbedContent with three panes, entitled 'tab-2', 'New tab' and 'New tab'
"""

class ExampleApp(App):
BINDINGS = [
Expand Down Expand Up @@ -2992,7 +2995,8 @@ async def run_before(pilot: Pilot) -> None:

def test_disable_command_palette(snap_compare):
"""Test command palette may be disabled by check_action.
You should see a footer with an enabled binding, and the command palette binding greyed out."""
You should see a footer with an enabled binding, and the command palette binding greyed out.
"""

class FooterApp(App):
BINDINGS = [("b", "bell", "Bell")]
Expand Down Expand Up @@ -3047,7 +3051,8 @@ def compose(self) -> ComposeResult:

def test_dock_align(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/5345
You should see a blue panel aligned to the top right of the screen, with a centered button."""
You should see a blue panel aligned to the top right of the screen, with a centered button.
"""

class MainContainer(Static):
def compose(self):
Expand Down Expand Up @@ -3335,7 +3340,8 @@ def compose(self) -> ComposeResult:
def test_arbitrary_selection_double_cell(snap_compare):
"""Check that selection understands double width cells.
You should see a smiley face followed by 'Hello World!', where Hello is highlighted."""
You should see a smiley face followed by 'Hello World!', where Hello is highlighted.
"""

class LApp(App):
def compose(self) -> ComposeResult:
Expand Down
8 changes: 6 additions & 2 deletions tests/test_styles_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,21 @@ def test_no_styles():
Color.parse("blue"),
Color.parse("green"),
content.__getitem__,
"",
"",
None,
None,
content_size=Size(3, 3),
)
style = Style.from_color(bgcolor=Color.parse("green").rich_color)

expected = [
Strip([Segment("foo", style)], 3),
Strip([Segment("bar", style)], 3),
Strip([Segment("baz", style)], 3),
]

print(lines[0])
print(expected[0])

assert lines == expected


Expand Down

0 comments on commit b055673

Please sign in to comment.