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 | |
| 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.
| -rw-r--r-- | config/config.kdl | 6 | ||||
| -rwxr-xr-x | contrib/shader-repl | 22 | ||||
| -rw-r--r-- | docs/keys.md | 7 | ||||
| -rw-r--r-- | docs/scripting.md | 6 | ||||
| -rw-r--r-- | docs/shaders.md | 17 | ||||
| -rw-r--r-- | src/app.c | 45 | ||||
| -rw-r--r-- | src/app.h | 10 | ||||
| -rw-r--r-- | src/cmd.c | 8 | ||||
| -rw-r--r-- | src/config.c | 4 | ||||
| -rw-r--r-- | src/config.h | 1 | ||||
| -rwxr-xr-x | tests/test_inband_shaders.py | 103 | ||||
| -rw-r--r-- | tests/test_palette.py | 19 |
12 files changed, 230 insertions, 18 deletions
diff --git a/config/config.kdl b/config/config.kdl index 95611c6..4ea6261 100644 --- a/config/config.kdl +++ b/config/config.kdl @@ -267,6 +267,10 @@ focus_follows_mouse true // cannot change anything this file said about everybody else. The pane is told // `off` rather than ignored, so a program can tell "you said no" from "this // build has never heard of it". +// +// The way back, whatever a pane did to itself and whether or not this is still +// true afterwards: the `clear-shaders` action (bind it, or run it from the +// palette), or `sl0ppty cmd '{"cmd":"clear-shaders","id":0}'`. in_band_shaders false // The floor below which a pane is not small but useless. A split that cannot @@ -677,7 +681,7 @@ theme { // // Actions: split-cols split-rows close-pane focus-left focus-right focus-up // focus-down focus-next resize-left resize-right resize-up resize-down equalize -// rotate-layout +// rotate-layout clear-shaders // scroll-up scroll-down scroll-page-up scroll-page-down scroll-top // scroll-bottom zoom minimize rerun new-tab next-tab prev-tab select-tab-1..9 finder // palette help detach quit diff --git a/contrib/shader-repl b/contrib/shader-repl index d69f8e7..537f3bb 100755 --- a/contrib/shader-repl +++ b/contrib/shader-repl @@ -211,16 +211,20 @@ def main(): print(" tab completes all of it; up/down and ctrl-r are history") continue if line in (":clear", ":both"): - targets = ["chrome", "content"] if line == ":both" else [where] - for target in targets: - tty.setraw(fd) - try: - msg, ok = ask(fd, target, "") - finally: - termios.tcsetattr(fd, termios.TCSADRAIN, saved) - if ok: + # `:both` names no rect, which the session reads as all of them: + # one exchange, and the pane cannot be left half put-back. + target = "" if line == ":both" else where + tty.setraw(fd) + try: + msg, ok = ask(fd, target, "") + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, saved) + if ok: + if target: chains[target] = "" - print("%s: %s" % (target, msg)) + else: + chains["chrome"] = chains["content"] = "" + print(msg) continue # raw only around the exchange, so the prompt keeps its line editing diff --git a/docs/keys.md b/docs/keys.md index 66163b5..a5befad 100644 --- a/docs/keys.md +++ b/docs/keys.md @@ -95,7 +95,7 @@ being bound at all. | group | actions | |---|---| -| panes | `split-cols` `split-rows` `close-pane` `rerun` `zoom` `minimize` `rotate-layout` | +| panes | `split-cols` `split-rows` `close-pane` `rerun` `zoom` `minimize` `rotate-layout` `clear-shaders` | | focus | `focus-left` `focus-right` `focus-up` `focus-down` `focus-next` `finder` | | size | `resize-left` `resize-right` `resize-up` `resize-down` `equalize` | | tabs | `new-tab` `next-tab` `prev-tab` `select-tab-1` … `select-tab-9` | @@ -103,4 +103,7 @@ being bound at all. | session | `palette` `help` `edit-config` `detach` `quit` `literal-prefix` | `scroll-up` and `scroll-down` have no default key — the wheel does that job — -which is exactly the case the palette exists for. +which is exactly the case the palette exists for. So does `clear-shaders`, which +undoes whatever the program in a pane painted on it +([shaders](shaders.md#prototyping-in-a-pane)); bind it if you leave +`in_band_shaders` on. diff --git a/docs/scripting.md b/docs/scripting.md index 298ae17..0f398ff 100644 --- a/docs/scripting.md +++ b/docs/scripting.md @@ -29,6 +29,7 @@ Panes and tabs are addressed by **id**, so a background tab is scriptable. | `split` | `dir:"cols"\|"rows"`, `id` for which pane to split | | `focus` | `id` | | `close` `rerun` | `id`, or 0 for the focused pane | +| `clear-shaders` | `id`, or 0 for the focused pane; answers `cleared:0\|1` — the way back from a pane that painted itself unreadable | | `new-tab` `select-tab` `close-tab` `move-tab` `set-name` | tabs, by `id` or `index` | | `set-purpose` | `target:"pane"\|"tab"`, `id`, `purpose` | | `dump-layout` `apply-layout` | see [layouts](layouts.md) | @@ -61,7 +62,10 @@ declared by a layout or the control API wins and cannot be overwritten this way. `shader` is the third, and the only one the session can refuse: it sets the shader chain for the pane that asked, in the config's own syntax, and needs `in_band_shaders true` because a program restyling your session is a hazard -before it is a convenience. See [shaders](shaders.md#prototyping-in-a-pane). +before it is a convenience. `shader;` with no rect named clears both of that +pane's chains, which is never refused -- and `clear-shaders` above is the same +thing from outside, for a program that will not do it itself. +See [shaders](shaders.md#prototyping-in-a-pane). Anything the session sends *back* to a program ends its verb in `-reply` -- `hello-reply`, `shader-reply` -- and no request verb may. A pane that echoes what diff --git a/docs/shaders.md b/docs/shaders.md index 63801db..bb0221d 100644 --- a/docs/shaders.md +++ b/docs/shaders.md @@ -96,7 +96,8 @@ set the chains for the pane it is running in, in the same syntax the config uses ```bash printf '\033]5577;1;shader;chrome;tint color="#ff5fd7" amount="abs(t / 8 %% 510 - 255)"\033\\' printf '\033]5577;1;shader;content;dim amount=90\033\\' -printf '\033]5577;1;shader;chrome;\033\\' # nothing: back to normal +printf '\033]5577;1;shader;chrome;\033\\' # that rect: back to normal +printf '\033]5577;1;shader;\033\\' # no rect named, so both of them ``` The field after `shader` is which rect (`content` or `chrome`), and the rest of @@ -105,6 +106,20 @@ on one line. The session answers on the program's stdin, `\033]5577;1;shader-rep or `shader-reply;error;bad amount for tint: ...`, so a typo says so instead of looking like a shader that does nothing. +**Three ways to take it all back**, because the program that painted a pane is +not always in a state to put it back: + +| | | +|---|---| +| `printf '\033]5577;1;shader;\033\\'` | from the program, one exchange, both rects | +| `sl0ppty cmd '{"cmd":"clear-shaders","id":3}'` | from outside; `id` 0 or absent means the focused pane | +| the `clear-shaders` action | on a key you bind, or from the palette | + +None of them is gated on `in_band_shaders`. A chain can outlive the setting that +allowed it -- paint a pane, then turn the setting off -- and a way out that the +setting can take away is not one. They clear what the *pane* set: the config's own +chains and the session's own dimming are not this pane's doing. + `contrib/shader-repl` is that loop with a prompt on it: type a chain, see the pane change, and `:paste` prints what you have as a `shaders { }` block for your config. What you prototype and what you paste are parsed by the same code, which @@ -432,6 +432,20 @@ static void on_pane_shader(app_t *a, pane_t *p, const char *payload) { bool content = wlen == 7 && memcmp(payload, "content", 7) == 0; char reply[256]; + struct bypane b = {p, NULL}; + walk_all(a, bypane_cb, &b); + if (!b.found) return; + + /* Naming no rect means all of them: `shader;` puts the pane back in one + * exchange. The degenerate case of "which rect" rather than a verb of its own, + * because `shader;chrome;` and `shader;content;` already mean "this rect, this + * chain" and "" is the honest name for both of them. */ + if (!wlen) { + app_clear_pane_shaders(a, b.found->id); + snprintf(reply, sizeof reply, "\033]5577;1;shader-reply;ok\033\\"); + pane_write(p, reply, strlen(reply)); + return; + } if (!chrome && !content) { snprintf(reply, sizeof reply, "\033]5577;1;shader-reply;error;where must be content or chrome\033\\"); @@ -439,10 +453,6 @@ static void on_pane_shader(app_t *a, pane_t *p, const char *payload) { return; } - struct bypane b = {p, NULL}; - walk_all(a, bypane_cb, &b); - if (!b.found) return; - char err[192] = {0}; const char *text = semi ? semi + 1 : ""; bool ok = app_set_pane_shaders(a, b.found->id, chrome, text, err, sizeof err); @@ -2885,6 +2895,26 @@ static void draw_collapsed(app_t *a, screen_t *s, node_t *n) { * Refused, with a reason, when `in_band_shaders` is off -- a program restyling * itself by accident is exactly what that decision was about, and the answer is * a line of config rather than a rule nobody can lift. */ +/* Everything this pane painted on itself, gone: both chains at once. + * + * Not gated on `in_band_shaders`, unlike setting one. A chain can outlive the + * consent that allowed it -- set it, then turn the setting off, and the paint is + * still there -- so the way out must not be the thing the setting controls. It is + * also the operator's answer to a pane that has made itself unreadable, and an + * answer you have to edit a config to reach is not one. + * + * Says nothing about the config's own chains or the session's policy passes: + * those are not this pane's doing and are derived every frame anyway. */ +bool app_clear_pane_shaders(app_t *a, uint32_t pane_id) { + node_t *n = pane_by_id(a, pane_id ? pane_id : app_focused_pane_id(a)); + if (!n) return false; + bool had = n->content_chain.n || n->chrome_chain.n; + chain_clear(&n->content_chain); + chain_clear(&n->chrome_chain); + if (had) pane_touch(n->pane); + return had; +} + bool app_set_pane_shaders(app_t *a, uint32_t pane_id, bool chrome, const char *text, char *err, size_t errcap) { if (err && errcap) err[0] = 0; @@ -4789,6 +4819,13 @@ static bool run_action(app_t *a, action_t act) { case ACT_RESIZE_RIGHT: resize_focus(a, 1, 0); return true; case ACT_RESIZE_UP: resize_focus(a, 0, -1); return true; case ACT_RESIZE_DOWN: resize_focus(a, 0, 1); return true; + case ACT_CLEAR_SHADERS: + /* Says which of the two happened. "Nothing to undo" and "undone" look + * identical on a pane that was never painted, and a key that might have + * done nothing is a key you press again. */ + app_toast(a, app_clear_pane_shaders(a, 0) ? "shaders cleared" + : "no shaders on this pane"); + return true; case ACT_EQUALIZE: if (!app_equalize_splits(a)) app_toast(a, "nothing to even out"); return true; @@ -148,6 +148,16 @@ uint32_t app_current_tab_id(app_t *a); bool app_set_pane_shaders(app_t *a, uint32_t pane_id, bool chrome, const char *text, char *err, size_t errcap); +/* Undo both of one pane's own chains. 0 means the focused pane. False when there + * was nothing to undo, so a caller can say so rather than flash a frame nobody + * changed. + * + * Deliberately not gated on `in_band_shaders`: a chain can outlive the consent + * that allowed it, and the way out must not be the thing the setting controls. + * Leaves the config's chains and the session's policy passes alone -- neither is + * this pane's doing. */ +bool app_clear_pane_shaders(app_t *a, uint32_t pane_id); + /* The session written back out as a layout file: tabs, splits, proportions, * directories and commands. The inverse of app_apply_layout_text(), and what * makes "quit, rebuild, come back to the same screen" possible. Caller frees. @@ -168,6 +168,14 @@ static char *cmd_json(app_t *a, screen_t *s, input_parser_t *in, return jerr("no such pane"); return jok_int(NULL, 0); } + /* The way in from outside the pane, for when the program that painted it will + * not or cannot put it back. `ok` either way, with `cleared` saying whether + * there was anything there: a script asking for a clean pane got one, and that + * is not an error. */ + if (strcmp(cmd, "clear-shaders") == 0) { + bool had = app_clear_pane_shaders(a, (uint32_t)jv_geti(req, "id", 0)); + return jok_int("cleared", had ? 1 : 0); + } if (strcmp(cmd, "new-tab") == 0) { uint32_t id = app_new_tab(a, jv_gets(req, "name", "")); if (!id) return jerr("cannot create tab"); diff --git a/src/config.c b/src/config.c index 70667ba..24837cb 100644 --- a/src/config.c +++ b/src/config.c @@ -24,6 +24,7 @@ static const struct { {"resize-left", ACT_RESIZE_LEFT}, {"resize-right", ACT_RESIZE_RIGHT}, {"resize-up", ACT_RESIZE_UP}, {"resize-down", ACT_RESIZE_DOWN}, {"equalize", ACT_EQUALIZE}, + {"clear-shaders", ACT_CLEAR_SHADERS}, {"rotate-layout", ACT_ROTATE_LAYOUT}, {"scroll-up", ACT_SCROLL_UP}, {"scroll-down", ACT_SCROLL_DOWN}, {"scroll-page-up", ACT_SCROLL_PAGE_UP}, @@ -829,6 +830,9 @@ static const struct { /* Short enough to fit the palette's label column, which truncates at 26 — * "give every pane an even share" read as "give every pane an even sh". */ {ACT_EQUALIZE, "size", "even out every split"}, + /* Under `panes`, not `size`: it undoes what the program in the pane did to + * the pane, which is a fact about that pane and not about the layout. */ + {ACT_CLEAR_SHADERS, "panes", "clear this pane's shaders"}, {ACT_ROTATE_LAYOUT, "size", "turn the layout a quarter"}, {ACT_NEW_TAB, "tabs", "new tab"}, diff --git a/src/config.h b/src/config.h index 815b58a..17c759c 100644 --- a/src/config.h +++ b/src/config.h @@ -70,6 +70,7 @@ typedef enum { ACT_RESIZE_UP, ACT_RESIZE_DOWN, ACT_EQUALIZE, + ACT_CLEAR_SHADERS, ACT_DETACH, ACT_QUIT, ACT_HELP, 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() |
