aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-15 23:06:32 +0200
committeruser <user@clank>2026-08-15 23:06:32 +0200
commitf6281fbec93d92bfc7e9164492e436d0236d9179 (patch)
treec78b435dec7f62c948e2e8144f29f47ccab2fa7d /contrib
parentsl0ppty: a command palette, on a key you choose (diff)
downloadslosh-f6281fbec93d92bfc7e9164492e436d0236d9179.tar.gz
slosh-f6281fbec93d92bfc7e9164492e436d0236d9179.tar.xz
slosh-f6281fbec93d92bfc7e9164492e436d0236d9179.zip
sl0ppty: shaders on the chrome, and two keys for the arrangement
Five things, in one commit because they land in the same few files -- the action table, the shader pass, config.kdl -- and splitting them by hunk would buy a tidier log at the price of commits that do not build. Each is verified end to end; the suite is 46 files green. Chrome shaders. `where="chrome"` on any entry in `shaders` or in a `states` block runs that pass over a pane's frame -- border, padding, title, buttons -- instead of its contents. Nothing else changes: same registry, same `amount`, same expressions, same chain order, one new word, because a frame is another rect and so it is another pass. It runs over the frame's whole rect with the contents punched out as a hole, rather than four passes over four sides: an effect has to be able to travel round a border, and four passes would each count x/y from zero and restart at every corner. The hole keeps the two honest -- a skipped cell is never visited, so a full-strength chrome tint cannot reach your text. It is also the only kind of pass that can colour a pane a small window has collapsed to a single row (D6), which is the state where a colour is worth the most. `channel="fg"|"bg"|"both"` came out of looking at the first border flash: `tint` mixes both of a cell's colours, and a frame's background is the terminal's own default, so the pass materialised it to our guess at that default and mixed towards the colour -- a dark rectangle behind the glyphs, left there until the pane changed state. The mask is enforced by the pass, not the shader: the other colour is snapshotted before materialising and put back after, so an unset colour goes back to unset, it works for a built-in and a plugin alike, and no shader grows an fg-only twin of itself. A `bell` pane state and a `since` variable, because "flash the border when a pane rings" needed both and neither existed. `since` is milliseconds since the pane entered its current state, stamped in the one function that decides the state -- a transition is the one thing a frame cannot tell you, so it is remembered where it cannot disagree with the state it dates. `bell` ranks above the ambient states and below `dead`: a pane that rang while you were elsewhere is news, and a pane that rang and then exited is a pane that exited. It ends when you look at the pane, because that is what answering a bell is. Animation needed a clock and did not have one: a shader reading `t` only advanced when something else caused a frame, so a pulse froze the moment you stopped typing. `app_next_deadline_ms` now reports `anim_ms` while a chain that reads the clock ran over the last frame -- derived from what was applied, so a pulse hung off `dead` costs a clock while a pane is dead and nothing for the rest of the session. A `deadline` verb makes that observable; the server's poll loop already lived on the number. contrib/chrome has seven presets and the perimeter trick they are built on: on a frame the coordinate you want is distance along the ring, which the language can work out, and `min(d, P - d)` is what makes an effect cross the corner it started from. Hand-written, unlike contrib/shaders, because the toy previews contents and a frame has no preview to give -- so tests/test_chrome_presets.py checks each one the only way left: load it into a real session, assert the frame moves and the contents do not. `equalize` (C-a =) puts every share back to even: each split's children weighted by how many visible panes are behind them, so one pane beside a stack of three is a quarter of the width and "even" means the same thing at every depth. Exactly equal cell counts are not something a tree can always express, so the action promises the even division it can. `rotate-layout` (C-a Space) turns the whole tab a quarter turn clockwise. Every split changes axis and a row split's children reverse, because the pane on top of a stack is the pane on the right once you turn it; get that asymmetry wrong and you have a mirror image, which looks almost right until four turns fail to come back. They do come back, exactly, which is why the inverse is three more turns rather than a second mirrored routine with its own chance of being wrong -- and why a key as easy as space is the right one rather than a hazard. A turn is refused when it would not fit: a share of the height is not always a share the width can afford, and a node that cannot give its children their floor takes the whole tab down to a list. So the turn is tried, the layout is asked what it made of it, and one that flattened the tab is put back with a word. Same rule `split_fits` applies to splitting. Keys: the palette moves from `shift+p` to `p`, and cycling tabs from `n`/`p` to tab/shift+tab. `p` is pressed far more often than "the tab before this one" and was the only shifted letter in the defaults; tab is what every other tabbed thing cycles with, and `\e[Z` decodes as shift+tab on a plain terminal, so this costs nothing on a client without the kitty protocol. `n` is free again. The actions are untouched: two lines of config put the old binds back. The shader ABI goes to 3: `shade_ctx_t` gained `state_ms` and struct shader gained `channels`, both the pass's business rather than a shader's. Plugins need a rebuild, which is what the version is for.
Diffstat (limited to 'contrib')
-rw-r--r--contrib/chrome/README.md85
-rw-r--r--contrib/chrome/corner-glints.kdl18
-rw-r--r--contrib/chrome/gradient.kdl20
-rw-r--r--contrib/chrome/ripple.kdl19
-rw-r--r--contrib/chrome/shimmer.kdl19
-rw-r--r--contrib/chrome/shine.kdl19
-rw-r--r--contrib/chrome/spinner.kdl19
-rw-r--r--contrib/chrome/title-sheen.kdl18
-rw-r--r--contrib/shadertoy.html12
9 files changed, 228 insertions, 1 deletions
diff --git a/contrib/chrome/README.md b/contrib/chrome/README.md
new file mode 100644
index 0000000..12f275f
--- /dev/null
+++ b/contrib/chrome/README.md
@@ -0,0 +1,85 @@
+# chrome presets
+
+Colour passes over a pane's **frame** rather than its contents — `where="chrome"`
+— each in its own file, ready to paste into `~/.config/sl0ppty/config.kdl`.
+
+```sh
+cat contrib/chrome/shine.kdl >> ~/.config/sl0ppty/config.kdl # then save
+```
+
+Hand-written, unlike [`contrib/shaders`](../shaders), which is generated from
+`contrib/shadertoy.html`: the toy previews a pane's contents, and a frame is a
+different rect with no preview to give. So these are checked the only way that
+means anything — `tests/test_chrome_presets.py` loads every file here into a
+real session and asserts that the frame moves and the contents do not.
+
+| file | what it does |
+|---|---|
+| `shine.kdl` | a highlight running clockwise round the border, wrapping at the corner |
+| `shimmer.kdl` | sparkles drifting along it |
+| `ripple.kdl` | two pulses leaving the top-left corner and meeting at the far side |
+| `spinner.kdl` | a fixed arc rotating — work in progress, for a state |
+| `gradient.kdl` | not animated: lit from the top-left, so the frame reads as a surface |
+| `corner-glints.kdl` | the four corners breathing together |
+| `title-sheen.kdl` | the top rule only, where the title sits |
+
+## the perimeter trick
+
+On a frame, `x`/`y` are rarely what you want. An effect that travels round a
+border wants **distance along the ring**, and the language can work it out —
+clockwise from the top-left corner, in cells:
+
+```
+(y == 0 ? x
+ : x == cols-1 ? cols - 1 + y
+ : y == rows-1 ? 2 * cols + rows - 3 - x
+ : 2 * cols + 2 * rows - 4 - y)
+```
+
+The perimeter itself is `2 * cols + 2 * rows - 4`. Two things fall out of it:
+
+- **wrapping.** `min(d, P - d)` is distance the short way round, so an effect
+ crosses the corner it started from instead of stopping at a seam.
+- **direction.** `(p - head + P) % P` is "how far ahead of the head", which is
+ what makes an arc rotate rather than a blob slide.
+
+There is no way to name a subexpression, so the formula is written out in full
+in each file. That is the ugly part of these, and the reason the files are long
+when the effects are small.
+
+## two rules worth knowing
+
+**`channel="fg"`, always, on a frame.** A border's *background* is the
+terminal's own default; mixing that towards a colour paints a rectangle behind
+the glyphs instead of colouring them, and leaves it there. `fg` also keeps the
+padding inside the border out of it, since a blank cell has no foreground to
+colour — so the effect lands on exactly the rules, the title and the buttons.
+
+**Anything that reads `t` asks the session to keep painting** (`anim_ms`, 20fps
+by default) for as long as the pass is running. On a state that is the point: a
+pulse hung off `bell` or `dead` costs a frame clock while a pane is ringing or
+finished, and nothing for the rest of the session. Hung off every pane, as these
+files do for previewing, it costs that clock for the whole session — which is
+fine for a laptop and worth knowing about on a battery.
+
+`gradient.kdl` reads no clock at all: it is computed once into a per-cell map
+and reused, so it costs nothing per frame.
+
+## states
+
+Any of these is a state chain away from meaning something rather than just
+looking like something:
+
+```kdl
+states {
+ // the arc turns while a pane has not been started yet
+ suspended { tint where="chrome" channel="fg" color="#ffcc00" amount="…spinner…" }
+ // and a bell nobody has answered flashes, then settles
+ bell { tint where="chrome" channel="fg" color="#ffcc00" amount="(since < 250) * 255" }
+}
+```
+
+`since` is how long the pane has been in its current state, which is what makes
+a one-shot effect possible: `t` says what time it is, not how long ago something
+happened. The full list of states, and what each one means, is in
+`config/config.kdl`.
diff --git a/contrib/chrome/corner-glints.kdl b/contrib/chrome/corner-glints.kdl
new file mode 100644
index 0000000..799d58d
--- /dev/null
+++ b/contrib/chrome/corner-glints.kdl
@@ -0,0 +1,18 @@
+// corner glints — chrome
+//
+// Hand-written, unlike contrib/shaders: those are generated from
+// contrib/shadertoy.html, and the toy previews a pane's *contents*. A frame is
+// a different rect and the toy has no frame to show.
+//
+// Drop this into ~/.config/sl0ppty/config.kdl (a running session picks it up
+// when you save), or point $SL0PPTY_CONFIG at this file. To hang it off a pane
+// state instead of every pane, put the same pass inside one:
+//
+// states { bell { ... } }
+//
+// The four corners breathe together, brightest at the corner itself. `dist`
+// counts a row double, so the glint is round rather than an ellipse.
+
+shaders {
+ tint where="chrome" channel="fg" color="#ffffff" amount="clamp(220 - min(min(dist(x, y, 0, 0), dist(x, y, cols - 1, 0)), min(dist(x, y, 0, rows - 1), dist(x, y, cols - 1, rows - 1))) * 55, 0, 220) * (55 + abs(t / 3 % 90 - 45)) / 100"
+}
diff --git a/contrib/chrome/gradient.kdl b/contrib/chrome/gradient.kdl
new file mode 100644
index 0000000..16040b5
--- /dev/null
+++ b/contrib/chrome/gradient.kdl
@@ -0,0 +1,20 @@
+// gradient — chrome
+//
+// Hand-written, unlike contrib/shaders: those are generated from
+// contrib/shadertoy.html, and the toy previews a pane's *contents*. A frame is
+// a different rect and the toy has no frame to show.
+//
+// Drop this into ~/.config/sl0ppty/config.kdl (a running session picks it up
+// when you save), or point $SL0PPTY_CONFIG at this file. To hang it off a pane
+// state instead of every pane, put the same pass inside one:
+//
+// states { bell { ... } }
+//
+// Not animated: the border is simply brightest at the top-left corner and falls
+// away round both sides, so the frame reads as lit from somewhere rather than
+// drawn in one flat colour. Costs nothing per frame -- it does not read the
+// clock, so the whole pass is computed once into a map and reused.
+
+shaders {
+ tint where="chrome" channel="fg" color="#ffffff" amount="235 - min((y == 0 ? x : x == cols - 1 ? cols - 1 + y : y == rows - 1 ? 2 * cols + rows - 3 - x : 2 * cols + 2 * rows - 4 - y), (2 * cols + 2 * rows - 4) - (y == 0 ? x : x == cols - 1 ? cols - 1 + y : y == rows - 1 ? 2 * cols + rows - 3 - x : 2 * cols + 2 * rows - 4 - y)) * 255 / (cols + rows - 2)"
+}
diff --git a/contrib/chrome/ripple.kdl b/contrib/chrome/ripple.kdl
new file mode 100644
index 0000000..527ca1e
--- /dev/null
+++ b/contrib/chrome/ripple.kdl
@@ -0,0 +1,19 @@
+// ripple — chrome
+//
+// Hand-written, unlike contrib/shaders: those are generated from
+// contrib/shadertoy.html, and the toy previews a pane's *contents*. A frame is
+// a different rect and the toy has no frame to show.
+//
+// Drop this into ~/.config/sl0ppty/config.kdl (a running session picks it up
+// when you save), or point $SL0PPTY_CONFIG at this file. To hang it off a pane
+// state instead of every pane, put the same pass inside one:
+//
+// states { bell { ... } }
+//
+// Two pulses leaving the top-left corner in opposite directions and meeting at
+// the far side. The radius sweeps 0..half the perimeter, which is as far as a
+// ring goes before the two halves meet.
+
+shaders {
+ tint where="chrome" channel="fg" color="#7aa2f7" amount="(abs(min((y == 0 ? x : x == cols - 1 ? cols - 1 + y : y == rows - 1 ? 2 * cols + rows - 3 - x : 2 * cols + 2 * rows - 4 - y), (2 * cols + 2 * rows - 4) - (y == 0 ? x : x == cols - 1 ? cols - 1 + y : y == rows - 1 ? 2 * cols + rows - 3 - x : 2 * cols + 2 * rows - 4 - y)) - (t / 18 % (cols + rows - 2))) < 3) * 220"
+}
diff --git a/contrib/chrome/shimmer.kdl b/contrib/chrome/shimmer.kdl
new file mode 100644
index 0000000..1e9e972
--- /dev/null
+++ b/contrib/chrome/shimmer.kdl
@@ -0,0 +1,19 @@
+// shimmer — chrome
+//
+// Hand-written, unlike contrib/shaders: those are generated from
+// contrib/shadertoy.html, and the toy previews a pane's *contents*. A frame is
+// a different rect and the toy has no frame to show.
+//
+// Drop this into ~/.config/sl0ppty/config.kdl (a running session picks it up
+// when you save), or point $SL0PPTY_CONFIG at this file. To hang it off a pane
+// state instead of every pane, put the same pass inside one:
+//
+// states { bell { ... } }
+//
+// Sparkles drifting along the border. The `% 19 < 2` is a cheap pseudo-pattern
+// rather than a random number: the language has no rand, and a stride that does
+// not divide the perimeter never repeats where you can see it.
+
+shaders {
+ tint where="chrome" channel="fg" color="#ffffff" amount="(((y == 0 ? x : x == cols - 1 ? cols - 1 + y : y == rows - 1 ? 2 * cols + rows - 3 - x : 2 * cols + 2 * rows - 4 - y) * 7 + t / 40) % 19 < 2) * 210"
+}
diff --git a/contrib/chrome/shine.kdl b/contrib/chrome/shine.kdl
new file mode 100644
index 0000000..335fb3d
--- /dev/null
+++ b/contrib/chrome/shine.kdl
@@ -0,0 +1,19 @@
+// shine — chrome
+//
+// Hand-written, unlike contrib/shaders: those are generated from
+// contrib/shadertoy.html, and the toy previews a pane's *contents*. A frame is
+// a different rect and the toy has no frame to show.
+//
+// Drop this into ~/.config/sl0ppty/config.kdl (a running session picks it up
+// when you save), or point $SL0PPTY_CONFIG at this file. To hang it off a pane
+// state instead of every pane, put the same pass inside one:
+//
+// states { bell { ... } }
+//
+// A highlight running clockwise round the border, wrapping at the corner it
+// started from. `min(d, P - d)` is what makes it wrap: distance the short way
+// round a ring, rather than along a line that stops.
+
+shaders {
+ tint where="chrome" channel="fg" color="#ffffff" amount="clamp(235 - min(abs((y == 0 ? x : x == cols - 1 ? cols - 1 + y : y == rows - 1 ? 2 * cols + rows - 3 - x : 2 * cols + 2 * rows - 4 - y) - (t / 14 % (2 * cols + 2 * rows - 4))), (2 * cols + 2 * rows - 4) - abs((y == 0 ? x : x == cols - 1 ? cols - 1 + y : y == rows - 1 ? 2 * cols + rows - 3 - x : 2 * cols + 2 * rows - 4 - y) - (t / 14 % (2 * cols + 2 * rows - 4)))) * 30, 0, 235)"
+}
diff --git a/contrib/chrome/spinner.kdl b/contrib/chrome/spinner.kdl
new file mode 100644
index 0000000..8f5d187
--- /dev/null
+++ b/contrib/chrome/spinner.kdl
@@ -0,0 +1,19 @@
+// spinner — chrome
+//
+// Hand-written, unlike contrib/shaders: those are generated from
+// contrib/shadertoy.html, and the toy previews a pane's *contents*. A frame is
+// a different rect and the toy has no frame to show.
+//
+// Drop this into ~/.config/sl0ppty/config.kdl (a running session picks it up
+// when you save), or point $SL0PPTY_CONFIG at this file. To hang it off a pane
+// state instead of every pane, put the same pass inside one:
+//
+// states { bell { ... } }
+//
+// A fixed arc rotating: fourteen cells of border, going round. Reads as work in
+// progress, so it belongs on a state -- `suspended` for a pane that has not
+// started, or `bell` for one that wants you.
+
+shaders {
+ tint where="chrome" channel="fg" color="#ffcc00" amount="(((y == 0 ? x : x == cols - 1 ? cols - 1 + y : y == rows - 1 ? 2 * cols + rows - 3 - x : 2 * cols + 2 * rows - 4 - y) - (t / 14 % (2 * cols + 2 * rows - 4)) + (2 * cols + 2 * rows - 4)) % (2 * cols + 2 * rows - 4) < 14) * 200"
+}
diff --git a/contrib/chrome/title-sheen.kdl b/contrib/chrome/title-sheen.kdl
new file mode 100644
index 0000000..5eabd0f
--- /dev/null
+++ b/contrib/chrome/title-sheen.kdl
@@ -0,0 +1,18 @@
+// title sheen — chrome
+//
+// Hand-written, unlike contrib/shaders: those are generated from
+// contrib/shadertoy.html, and the toy previews a pane's *contents*. A frame is
+// a different rect and the toy has no frame to show.
+//
+// Drop this into ~/.config/sl0ppty/config.kdl (a running session picks it up
+// when you save), or point $SL0PPTY_CONFIG at this file. To hang it off a pane
+// state instead of every pane, put the same pass inside one:
+//
+// states { bell { ... } }
+//
+// The top rule only, where the title sits: a sheen crossing it left to right.
+// `y == 0` picks the rule out; the rest of the frame is left alone.
+
+shaders {
+ tint where="chrome" channel="fg" color="#ffffff" amount="(y == 0) * clamp(235 - abs(x - (t / 12 % cols)) * 40, 0, 235)"
+}
diff --git a/contrib/shadertoy.html b/contrib/shadertoy.html
index d796d12..f17a984 100644
--- a/contrib/shadertoy.html
+++ b/contrib/shadertoy.html
@@ -101,6 +101,8 @@
<code>cols rows</code> the size of the pane<br>
<code>curx cury</code> the cursor (follows your mouse), <code>cursor</code> 0/1<br>
<code>focused</code> 0/1 &nbsp; <code>t</code> milliseconds<br>
+ <code>since</code> ms in the pane's current state (<code>bell</code>,
+ <code>dead</code>…); here it restarts every 3s so a flash is visible<br>
<code>+ - * / %</code> integer only; division by zero is 0<br>
<code>&lt; &gt; &lt;= &gt;= == != &amp;&amp; || !</code> give 0 or 1, so
<code>(x &lt; 10) * 200</code> is a rule<br>
@@ -138,6 +140,7 @@ const VARS = {
cursor: { dep: DEP.CURSOR },
focused: { dep: DEP.FOCUS },
t: { dep: DEP.TIME },
+ since: { dep: DEP.TIME },
};
const FNS = { min: 2, max: 2, abs: 1, clamp: 3, dist: 4 };
@@ -537,8 +540,15 @@ function draw(now) {
ctx.font = `${CH - 5}px ui-monospace, monospace`;
ctx.textBaseline = "top";
+ /* `since` is how long the pane has been in its current state. This preview
+ has no pane and no states, so it is simulated: the clock restarts every
+ three seconds, as if something rang again — which is the only way a
+ one-shot effect (a bell flash) is visible in a preview at all. Said out
+ loud in the legend, because a preview that quietly means something else
+ than the session does is worse than no preview. */
const env = { cols: COLS, rows: ROWS, curx: cursor.x, cury: cursor.y,
- cursor: 1, focused: 1, t: Math.floor(now), x: 0, y: 0 };
+ cursor: 1, focused: 1, t: Math.floor(now),
+ since: Math.floor(now) % 3000, x: 0, y: 0 };
for (let y = 0; y < ROWS; y++) {
const [colour, text] = SAMPLE[y] || ["", ""];