diff options
| author | user <user@clank> | 2026-08-16 15:05:02 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-16 15:05:02 +0200 |
| commit | ab8165a9717b4dd2b6dc750f504d4f67f6d9fdc6 (patch) | |
| tree | aca329fd1453a0739d714bcd190cd155780dd0ee /tests | |
| parent | sl0ppty: a prompt with a memory (diff) | |
| download | slosh-ab8165a9717b4dd2b6dc750f504d4f67f6d9fdc6.tar.gz slosh-ab8165a9717b4dd2b6dc750f504d4f67f6d9fdc6.tar.xz slosh-ab8165a9717b4dd2b6dc750f504d4f67f6d9fdc6.zip | |
sl0ppty: three ways back from a painted pane
printf '\033]5577;1;shader;\033\\' # from the program
sl0ppty cmd '{"cmd":"clear-shaders","id":0}' # from outside it
bind "z" "clear-shaders" # from the keyboard
`app_clear_pane_shaders` empties both of a pane's chains and says whether
there was anything there, which is what lets a key answer "shaders cleared"
or "no shaders on this pane" instead of maybe having done something.
In-band it is not a new verb: naming no rect means all of them. `shader;`
sits under `shader;chrome;` and `shader;content;` as the degenerate case of
"which rect", so a program puts a pane back in one exchange and cannot leave
it half done. `contrib/shader-repl`'s `:both` now uses that rather than two.
**None of the three is gated on `in_band_shaders`.** A chain outlives the
setting that allowed it -- paint a pane, then turn the setting off, and the
paint is still there, because a chain belongs to the pane and not to the file
(there is a test that reloads with it off and clears anyway). A way out that
the setting can take away is not a way out. The operator path matters for the
same reason: the program that made a pane unreadable is not always in a state
to put it back.
They clear what the *pane* set. The config's chains and the session's own
dimming are not this pane's doing and are derived every frame anyway.
The action is bound to nothing, like `scroll-up`: it is in the palette, which
is what the palette is for, and the docs say to bind it if you leave the
setting on. Which is where a second bug turned up -- the palette truncates a
label at 26 characters, so "undo this pane's own shaders" read as "undo this
pane's own shade" on screen. Renamed to fit, and `tests/test_palette.py` now
checks every label against the column, since nothing failed for that: it just
looked like a typo in front of someone.
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/test_inband_shaders.py | 103 | ||||
| -rw-r--r-- | tests/test_palette.py | 19 |
2 files changed, 122 insertions, 0 deletions
diff --git a/tests/test_inband_shaders.py b/tests/test_inband_shaders.py index 860e618..6743542 100755 --- a/tests/test_inband_shaders.py +++ b/tests/test_inband_shaders.py @@ -218,6 +218,105 @@ def test_a_refused_chain_leaves_the_last_good_one_standing(): os.unlink(path) +def test_naming_no_rect_clears_both(): + """`shader;` with no rect is every rect: one exchange puts the whole pane + back, rather than two that can leave it half done.""" + path = cfg("in_band_shaders true\n") + with Session(staged((osc('1;shader;chrome;tint color="#ff0033" amount=255') + + osc('1;shader;content;tint color="#ff0033" amount=255'), + "painted"), + (osc("1;shader;"), "bare")), + cols=64, rows=10, config=path) as s: + s.until_text("painted") + snap, p = s.snapshot(), s.pane() + check("both chains ran", + frame(snap, p)["fg"] == "#ff0033" + and snap.style_at(p["x"] + 1, p["y"] + 1)["fg"] == "#ff0033", + str(frame(snap, p))) + s.raw("\\n") + s.until_text("bare") + snap = s.snapshot() + body = snap.style_at(p["x"] + 1, p["y"] + 1) + check("naming no rect takes the frame back", + frame(snap, p)["fg"] != "#ff0033", str(frame(snap, p))) + check("...and the contents with it", not body or body["fg"] != "#ff0033", + str(body)) + os.unlink(path) + + +def test_it_can_be_cleared_from_outside_the_pane(): + """The operator's way out. A program that painted a pane unreadable may not + be in any state to put it back -- and `cleared` says whether there was + anything there, because asking for a clean pane and getting one is not an + error.""" + path = cfg("in_band_shaders true\n") + with Session(pane(osc('1;shader;chrome;tint color="#ff0033" amount=255')), + cols=64, rows=10, config=path) as s: + s.until_text("shader-reply") + p = s.pane() + check("painted", frame(s.snapshot(), p)["fg"] == "#ff0033", "") + first = s.api("clear-shaders", id=p["id"]) + s.settle(60) + check("the control API clears it", first.get("cleared") == 1, str(first)) + check("and the frame is the session's again", + frame(s.snapshot(), p)["fg"] != "#ff0033", + str(frame(s.snapshot(), p))) + again = s.api("clear-shaders", id=p["id"]) + check("a second call says there was nothing to clear", + again.get("ok") and again.get("cleared") == 0, str(again)) + os.unlink(path) + + +def test_a_key_can_undo_what_a_pane_did_to_itself(): + """Bound to nothing by default -- it is in the palette like every action -- + but it has to work on a key, because a pane you cannot read is not a pane you + want to go looking through a menu for.""" + path = cfg('in_band_shaders true\nkeys {\n bind "z" "clear-shaders"\n}\n') + with Session(pane(osc('1;shader;chrome;tint color="#ff0033" amount=255')), + cols=64, rows=10, config=path) as s: + s.until_text("shader-reply") + p = s.pane() + check("painted", frame(s.snapshot(), p)["fg"] == "#ff0033", "") + s.key("z") + s.settle(80) + snap = s.snapshot() + check("the key clears it", frame(snap, p)["fg"] != "#ff0033", + str(frame(snap, p))) + check("and says so", "shaders cleared" in snap.screen(), + repr(snap.screen()[-160:])) + s.key("z") + s.settle(80) + check("pressing it again says there was nothing to undo", + "no shaders on this pane" in s.snapshot().screen(), + repr(s.snapshot().screen()[-160:])) + os.unlink(path) + + +def test_clearing_works_even_with_the_setting_off(): + """A chain can outlive the consent that allowed it: painted while the setting + was on, and the session reloaded with it off. The way out must not be the + thing the setting controls.""" + path = cfg('in_band_shaders true\nkeys {\n bind "z" "clear-shaders"\n}\n') + with Session(pane(osc('1;shader;chrome;tint color="#ff0033" amount=255')), + cols=64, rows=10, config=path) as s: + s.until_text("shader-reply") + p = s.pane() + check("painted while it was allowed", + frame(s.snapshot(), p)["fg"] == "#ff0033", "") + open(path, "w").write('in_band_shaders false\nkeys {\n bind "z" "clear-shaders"\n}\n') + s.api("reload") + s.settle(60) + check("the paint survives the reload, being the pane's and not the file's", + frame(s.snapshot(), p)["fg"] == "#ff0033", + str(frame(s.snapshot(), p))) + s.key("z") + s.settle(80) + check("and it can still be cleared", + frame(s.snapshot(), p)["fg"] != "#ff0033", + str(frame(s.snapshot(), p))) + os.unlink(path) + + def test_it_is_off_unless_the_config_says_otherwise(): """The D13 default. A program that tries gets told no, which is the part that matters: silence would look like a build without the feature.""" @@ -283,6 +382,10 @@ if __name__ == "__main__": test_an_empty_chain_puts_the_pane_back() test_a_chain_that_does_not_read_is_refused_with_a_reason() test_a_refused_chain_leaves_the_last_good_one_standing() + test_naming_no_rect_clears_both() + test_it_can_be_cleared_from_outside_the_pane() + test_a_key_can_undo_what_a_pane_did_to_itself() + test_clearing_works_even_with_the_setting_off() test_it_is_off_unless_the_config_says_otherwise() test_a_pane_can_only_paint_itself() test_an_expression_animates() diff --git a/tests/test_palette.py b/tests/test_palette.py index b2ddb0b..2b81710 100644 --- a/tests/test_palette.py +++ b/tests/test_palette.py @@ -10,6 +10,8 @@ It shares its box, its keys and its mouse handling with the pane finder (they are one picker with a subject), so the navigation and editing checks live in test_finder.py and are not repeated here. """ +import pathlib +import re import sys import tempfile @@ -213,7 +215,24 @@ def test_the_finder_is_still_its_own_thing(): check("and the palette lists commands", is_open(s)) +def test_every_label_fits_the_column(): + """The palette's label column truncates at 26 and `config.c` says so beside + the table. A label one word too long does not fail anything -- it just reads + as a typo on screen ("undo this pane's own shade"), which is how this check + came to exist.""" + src = pathlib.Path(__file__).resolve().parent.parent / "src" / "config.c" + table = src.read_text() + table = table[table.index("ACTION_HELP[]"):] + table = table[:table.index("\n};")] + rows = re.findall(r'\{ACT_[A-Z_0-9]+, "([a-z]+)", "([^"]+)"\}', table) + long = [(g, l) for g, l in rows if len(l) > 26] + check("every action label fits the palette's column", not long, + str([(l, len(l)) for _, l in long])) + check("and the table was actually read", len(rows) > 20, str(len(rows))) + + if __name__ == "__main__": + test_every_label_fits_the_column() test_it_opens_and_lists_commands() test_it_lists_actions_that_have_no_key() test_typing_filters_it() |
