fix(frame): start the corner fade at the brightest palette stop
A ladder is a hue walk, not a brightness walk, so painting the hot end backwards put the dim colour at the corner. Sort the ramp by stock brightness and follow the pane height for the bottom-left glow.
This commit is contained in:
1 parent
81116282cb
commit
ec2ca72efb
4 files changed
+117
-39
No files matched your search
+38
-20
@@ -1,15 +1,17 @@
|
||||
"""The BBS frames: grey edges, corners fading white → grey → cyan."""
|
||||
"""The BBS frames: grey edges, and a short palette glow in two corners."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from rich.text import Text
|
||||
|
||||
from beefy_player.palettes import PALETTES
|
||||
from beefy_player.palettes import PALETTES, brightness
|
||||
from beefy_player.widgets import frame
|
||||
|
||||
#: The original ladder, used as a fixed reference in these tests.
|
||||
STOPS = PALETTES["spectrum"]
|
||||
HOT = STOPS[-1] # the corner colour
|
||||
#: Its glow: the brightest cell first, dimmer cells towards the edge.
|
||||
RAMP = frame.fade_ramp(STOPS)
|
||||
HOT = RAMP[0] # the corner colour
|
||||
|
||||
|
||||
def styles_of(line: Text) -> list[tuple[str, str]]:
|
||||
@@ -18,26 +20,29 @@ def styles_of(line: Text) -> list[tuple[str, str]]:
|
||||
]
|
||||
|
||||
|
||||
def test_the_corner_gets_the_brightest_colour_of_the_fade() -> None:
|
||||
ranks = [brightness(colour) for colour in RAMP]
|
||||
assert ranks == sorted(ranks, reverse=True)
|
||||
# spectrum's hot end is red, which is dimmer than the yellow before it:
|
||||
# the corner must still be the bright one, not the ladder's last stop
|
||||
assert STOPS[-1] != HOT
|
||||
assert brightness(HOT) > brightness(STOPS[-1])
|
||||
assert set(RAMP) <= set(STOPS)
|
||||
assert frame.corner_fade(len(RAMP), STOPS) == frame.EDGE
|
||||
|
||||
|
||||
def test_only_the_top_right_corner_fades_on_the_top_edge() -> None:
|
||||
spans = styles_of(frame.top(30, stops=STOPS))
|
||||
assert spans[0] == ("╭", frame.EDGE) # plain grey corner
|
||||
# the fade runs into the top-right corner, hot end last
|
||||
assert [style for _text, style in spans[-4:-1]] == [
|
||||
STOPS[-4],
|
||||
STOPS[-3],
|
||||
STOPS[-2],
|
||||
]
|
||||
# the fade runs into the top-right corner, brightest cell last
|
||||
assert [style for _text, style in spans[-4:-1]] == [RAMP[3], RAMP[2], RAMP[1]]
|
||||
assert spans[-1] == ("╮", f"bold {HOT}")
|
||||
|
||||
|
||||
def test_only_the_bottom_left_corner_fades_on_the_bottom_edge() -> None:
|
||||
spans = styles_of(frame.bottom(30, STOPS))
|
||||
assert spans[0] == ("╰", f"bold {HOT}")
|
||||
assert [style for _text, style in spans[1:4]] == [
|
||||
STOPS[-2],
|
||||
STOPS[-3],
|
||||
STOPS[-4],
|
||||
]
|
||||
assert [style for _text, style in spans[1:4]] == [RAMP[1], RAMP[2], RAMP[3]]
|
||||
assert spans[-1] == ("╯", frame.EDGE) # plain grey corner
|
||||
|
||||
|
||||
@@ -51,15 +56,15 @@ def test_the_sides_glow_towards_their_own_corner_only() -> None:
|
||||
frame.EDGE,
|
||||
frame.EDGE,
|
||||
frame.EDGE,
|
||||
STOPS[-4],
|
||||
STOPS[-3],
|
||||
STOPS[-2],
|
||||
RAMP[3],
|
||||
RAMP[2],
|
||||
RAMP[1],
|
||||
]
|
||||
# right column fades down from the top-right corner
|
||||
assert [frame.side_style(row, 10, "right", STOPS) for row in range(10)] == [
|
||||
STOPS[-2],
|
||||
STOPS[-3],
|
||||
STOPS[-4],
|
||||
RAMP[1],
|
||||
RAMP[2],
|
||||
RAMP[3],
|
||||
frame.EDGE,
|
||||
frame.EDGE,
|
||||
frame.EDGE,
|
||||
@@ -98,3 +103,16 @@ def test_content_wider_than_the_pane_is_trimmed_not_spilled() -> None:
|
||||
assert lines[1].endswith("│")
|
||||
# the original renderable is left untouched
|
||||
assert long_line.plain == "x" * 40
|
||||
|
||||
|
||||
def test_a_short_pane_still_glows_in_its_bottom_left_corner() -> None:
|
||||
"""The fade follows the pane's height, not the number of content rows."""
|
||||
group = frame.wrap([Text("one line")], 20, 6, stops=STOPS)
|
||||
lines = list(group.renderables)
|
||||
# rows 1-4 are the content box; the fade climbs its last three rows
|
||||
assert str(lines[1].spans[0].style) == frame.EDGE
|
||||
assert [str(line.spans[0].style) for line in lines[2:5]] == [
|
||||
RAMP[3],
|
||||
RAMP[2],
|
||||
RAMP[1],
|
||||
]
|
||||
Reference in new issue
Block a user