diff options
| author | user <user@clank> | 2026-08-19 13:46:57 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-19 13:46:57 +0200 |
| commit | 42b3c10995eb67778d9dd3aa2fd80624896acd5f (patch) | |
| tree | 751bcb8604967dc8687cf23fbeb1033aa26ca427 | |
| parent | slosh: a website that is a page, not a mock session (diff) | |
| download | slosh-42b3c10995eb67778d9dd3aa2fd80624896acd5f.tar.gz slosh-42b3c10995eb67778d9dd3aa2fd80624896acd5f.tar.xz slosh-42b3c10995eb67778d9dd3aa2fd80624896acd5f.zip | |
slosh: defaults most people can live in, said by shaders
The out-of-the-box look, rethought as one piece:
- the compiled-in palette calms down: muted blue #7aa2f7 on the same
neutral darks, with the colours that mean something kept semantic --
amber bell, red-orange dead. sl0p stays one include away as the house
style, and contrib/themes/default.kdl is the starting point written
down (theme-tour shows it).
- derived state defaults now actually follow the theme: the scrolled
wash is rebuilt from scroll_bg after the theme block (it used to bake
the compiled accent), and declaring a state -- in any file of an
include chain -- still wins. The dump writes derived states as
comments so C-a e cannot pin what is meant to keep following.
- a bell you can see: the frame blinks three times in theme's bell
colour then breathes until answered, and a soft diagonal shimmer --
the bell colour halved towards default_fg, width breathing on a sine
-- crosses the body for the same 900ms. bell_indicator false silences
all of it; states { bell { } } replaces it like any state. since
carries the clock dependency, so an idle session pays nothing.
- scrollback says where it continues: while scrolled, the viewport's
top and bottom rows melt towards an edge with content past it and
turn solid at the buffer's end. New expression variables above/below
(lines hidden past each edge, own dependency bit, cached per scroll
position), carried in shade_ctx_t -- SLOSH_SHADER_ABI 3 -> 4.
- expressions survive the dump: a program keeps its source and cb_chain
writes it back, so amount="(y % 2) * 40" no longer dumps as a number.
- headers move to include/, -Iinclude everywhere; the plugin Makefile's
SLOSH var becomes SLOSH_DIR because slosh exports SLOSH=1 into every
pane it runs, and building from inside a session read that as a path.
- comment drift culled where features outran the prose, and the
derivation boilerplate folded into derived_pass()/ctx_scroll().
| -rw-r--r-- | DESIGN.md | 4 | ||||
| -rw-r--r-- | Makefile | 15 | ||||
| -rw-r--r-- | config/config.kdl | 138 | ||||
| -rw-r--r-- | contrib/README.md | 22 | ||||
| -rw-r--r-- | contrib/shader-plugin/Makefile | 11 | ||||
| -rw-r--r-- | contrib/shader-plugin/README.md | 2 | ||||
| -rwxr-xr-x | contrib/shader-repl | 15 | ||||
| -rw-r--r-- | contrib/themes/default.kdl | 81 | ||||
| -rw-r--r-- | contrib/themes/sl0p.kdl | 4 | ||||
| -rw-r--r-- | docs/chrome.md | 7 | ||||
| -rw-r--r-- | docs/config.md | 9 | ||||
| -rw-r--r-- | docs/shaders.md | 7 | ||||
| -rw-r--r-- | include/app.h (renamed from src/app.h) | 0 | ||||
| -rw-r--r-- | include/cmd.h (renamed from src/cmd.h) | 0 | ||||
| -rw-r--r-- | include/config.h (renamed from src/config.h) | 10 | ||||
| -rw-r--r-- | include/expr.h (renamed from src/expr.h) | 17 | ||||
| -rw-r--r-- | include/graphics.h (renamed from src/graphics.h) | 0 | ||||
| -rw-r--r-- | include/input.h (renamed from src/input.h) | 0 | ||||
| -rw-r--r-- | include/json.h (renamed from src/json.h) | 0 | ||||
| -rw-r--r-- | include/jsonval.h (renamed from src/jsonval.h) | 0 | ||||
| -rw-r--r-- | include/kdl.h (renamed from src/kdl.h) | 0 | ||||
| -rw-r--r-- | include/osc5577.h (renamed from src/osc5577.h) | 0 | ||||
| -rw-r--r-- | include/png.h (renamed from src/png.h) | 0 | ||||
| -rw-r--r-- | include/project.h (renamed from src/project.h) | 0 | ||||
| -rw-r--r-- | include/proto.h (renamed from src/proto.h) | 0 | ||||
| -rw-r--r-- | include/server.h (renamed from src/server.h) | 0 | ||||
| -rw-r--r-- | include/shader.h (renamed from src/shader.h) | 0 | ||||
| -rw-r--r-- | include/shader_abi.h (renamed from src/shader_abi.h) | 7 | ||||
| -rw-r--r-- | include/slosh.h (renamed from src/slosh.h) | 0 | ||||
| -rw-r--r-- | src/app.c | 15 | ||||
| -rw-r--r-- | src/config.c | 238 | ||||
| -rw-r--r-- | src/expr.c | 24 | ||||
| -rw-r--r-- | src/shader.c | 2 | ||||
| -rw-r--r-- | tests/expr_test.c | 19 | ||||
| -rw-r--r-- | tests/test_bell.py | 125 | ||||
| -rwxr-xr-x | tests/test_chrome_shaders.py | 2 | ||||
| -rw-r--r-- | tests/test_config.py | 4 | ||||
| -rw-r--r-- | tests/test_drag.py | 2 | ||||
| -rw-r--r-- | tests/test_responsive.py | 2 | ||||
| -rw-r--r-- | tests/test_shaders.py | 4 | ||||
| -rw-r--r-- | tests/test_states.py | 113 | ||||
| -rw-r--r-- | tests/test_tabs.py | 2 | ||||
| -rw-r--r-- | tests/test_wide_marks.py | 5 |
43 files changed, 796 insertions, 110 deletions
@@ -158,11 +158,11 @@ unreadable. | **D13** | **Shaders are a colour pass over cells, and *which* cells is the pass's, not the shader's.** A shader is a pure function from (cell, position, parameters) to that cell's colours, run between `pane_compose()` and the split guide — so a content pass covers the contents and nothing else by paint order, not by a rule anyone has to remember. Frames are shaded by a pass of their own over a rect of their own (D19); no shader knows the difference, which is the point. Cells only: fg, bg and attrs may change, text and width may not, because rewriting text would desync selection and copy (which read the terminal, not the screen). Each cell is shaded independently, so positional effects are expressible and convolutions are not; that is the price of needing no second buffer. Shaders chain in order, each a complete pass. Attached per pane by internal policy only — not over the control API and not in-band, so a program cannot restyle itself. A cell whose colour is "terminal default" is materialised to a **configured** `default_fg`/`default_bg` first: we never learn the client's real default, and most text is default-coloured, so the alternative is a dimmer that visibly does nothing. Panes with no shader skip the pass entirely and still defer to the terminal. Which shader a pane gets from the session is a **table of states** — dragging, drop_hover, drop_target, dead, suspended, scrolled, unfocused — each naming a chain. A pane is usually in several at once, so exactly one wins: the first to match, in a fixed order running from the most deliberate to the most ambient. **Which states ship a default is a line, not a mood**: a pane that is *not live* gets one — dead, suspended, scrolled, where the cells are showing something other than a running program's present and nothing else would tell you. `unfocused` is a taste rather than a fact and gets one anyway, through a knob of its own (`dim_unfocused`) rather than through the table: the objection to shipping a taste was never the taste, it was that turning it off should not require knowing the states block exists, and a single number fixes that. Writing the chain by hand still wins over the knob, including writing an empty one. `dragging` keeps no default, because the pane in your hand keeping its colour is what makes it lift off the page. The corollary is that a collapsed header, which the pass never reaches because a header is chrome, has to carry those same three facts in words. Fixed rather than configured, because it is a ranking by urgency and not a preference. They do not stack, because two reasons to be grey compound into one muddy grey that reads as neither. `dead` is one of them because a pane whose program exits is now kept until it is dismissed (D14); it was excluded while there was no frame it could ever draw. All of it is **derived every frame, never attached and remembered**: focus and drags move through too many paths to keep an attachment in sync with, and a pane left grey by the one path that forgot to clear it is a bug that only appears in front of someone. Same rule as the rect and the collapsed flag. | | **D14** | **A pane that was given a command outlives it.** When such a program exits, the pane stays: it keeps everything it printed, writes two lines into its own backlog saying what it ran and how it ended (`[ran: npm run dev]`, `[process exited: status 3]`) -- the command because `[re-run]` is one button, and a pane that does not say what it would run makes pressing it a guess, most of all in a tab a project's layout built where the command was never typed into that pane to be scrolled back to; a pane running the session's shell has none to name and gets the exit line alone, says the same thing in its frame and in the status line, and offers the only two verbs still meaningful — `[re-run]` and `[close]`. Re-running spawns the same argv in the same cwd, in the *same pane*: same id, same place in the tree, same terminal, so the run that ended stays above the new one in the scrollback and nothing that referred to that pane has to be told anything. The old behaviour reaped the pane before the next paint, which meant the last thing a failing command printed vanished together with the status that would have explained it, and a mistyped command in a fresh session closed the session. Which panes this applies to is the *command*, not the provenance: a pane told to run something is part of the session's shape and its death is news, while a shell you split off is finished when you type `exit` and a corpse to dismiss there is fussiness. A shell is a shell whether a layout made it or a keystroke did, which also means a session restored from `dump-layout` behaves like the one it was dumped from. `keep_dead` moves the line: `all` keeps shells too, `none` keeps nothing. Two consequences are load-bearing rather than incidental: the pty fd is **closed** the moment EOF is seen, because an EOF fd left in the poll set is readable forever and would spin a session at 100% CPU behind a pane that looks idle; and the exit status is collected with a **bounded** wait, never a blocking one, because a program that closes its terminal and keeps running must not be able to hang the session — losing that race costs the words "status 0" and nothing else. | | **D15** | **Shaders may be loaded as native shared libraries**, from a directory beside the config. This is the one hole in D9 and it is argued for rather than drifted into (and D16 has since removed most of the *need* for it). A shader is called per cell, per pass, per frame — tens of thousands of times at up to 120Hz — so the subprocess model D9 prescribes cannot reach that path at all, and the measured alternative, interpreting a bytecode per cell, is 56ns against 8ns for the compiled function. What is loaded is also the narrowest possible thing: a pure function from one cell and its position to that cell's colours, unable to touch text, width, neighbours, panes or the session, because `shader_abi.h` is the only header it sees and nothing else is declared in it. On trust: the config file can already say `shell` and a layout can already say `command=`, so a file in the config directory can already run anything as you — a `.so` in the same directory is not a new boundary. It is refused unless it declares our ABI version *and* matching struct sizes, so a stale plugin fails at load instead of garbling colours. Nothing is ever unloaded: a `shade_fn` may be sitting in a live config or on a pane, so `dlclose()` would be a jump into an unmapped page — a reload therefore picks up newly *added* plugins only, and replacing one needs a new session. | -| **D16** | **A shader's `amount` may be an expression**, compiled to bytecode at config load. The scope is the argument: every built-in here is already `colour_op(amount)` with the amount a pure function of position, so the part worth handing to a config is the *number*, not the colour maths. That keeps mixing in C, gives an expression no way to produce an invalid cell (it produces one byte), and makes the result cacheable — a program that does not read the clock is evaluated once per cell into a map and reused until something it reads changes, so a config-written positional shader measures 5.2ns/cell against a compiled vignette's 6.1ns. Reading the clock costs 35ns/cell, per frame, which is the honest price of animation and is opt-in. The language is **total**: no loops, no recursion, no jumps — even `?:` evaluates both sides and selects, because nothing in it has an effect. So evaluation is O(program length), a config cannot spin, and there is nothing to sandbox; division by zero is 0 rather than a trap, because an expression that is wrong should look wrong rather than take the session with it. What a program reads is **derived by the compiler**, not declared, and that dependency set *is* the cache key — a stale map is unrepresentable rather than merely unlikely, which is the same rule the layout follows. An expression that does not compile drops that one shader with a warning: not the config, and not a half-strength version of what was asked for. | +| **D16** | **A shader's `amount` may be an expression**, compiled to bytecode at config load. The scope is the argument: every built-in here is already `colour_op(amount)` with the amount a pure function of position, so the part worth handing to a config is the *number*, not the colour maths. That keeps mixing in C, gives an expression no way to produce an invalid cell (it produces one byte), and makes the result cacheable — a program that does not read the clock is evaluated once per cell into a map and reused until something it reads changes, so a config-written positional shader measures 5.2ns/cell against a compiled vignette's 6.1ns. Reading the clock costs 35ns/cell, per frame, which is the honest price of animation and is opt-in. The language is **total**: no loops, no recursion, no jumps — even `?:` evaluates both sides and selects, because nothing in it has an effect. So evaluation is O(program length), a config cannot spin, and there is nothing to sandbox; division by zero is 0 rather than a trap, because an expression that is wrong should look wrong rather than take the session with it. What a program reads is **derived by the compiler**, not declared, and that dependency set *is* the cache key — a stale map is unrepresentable rather than merely unlikely, which is the same rule the layout follows. An expression that does not compile drops that one shader with a warning: not the config, and not a half-strength version of what was asked for. **`above`/`below` joined the environment for the scrolled edge fades**: lines of scrollback hidden past the viewport's top and bottom edges, read from the same scrollbar the ▲ indicator uses, with a dependency bit of their own (`EXPR_DEP_SCROLL`) so a cached map is keyed on the scroll position and reused while it holds still — they change per scroll event, not per frame, so they cost no clock. The compiled-in `scrolled` default uses them to melt the viewport's top and bottom rows where content continues, `min(3, rows / 4)` deep so a short viewport is not all fade; `(above > 0)` is a binary gate, so the edge you cannot scroll past renders solid, which is the message. They ride in `shade_ctx_t`, so `SLOSH_SHADER_ABI` went 3→4. | | **D17** | **Images need pixels, and we were not carrying any.** Kitty graphics worked in the test suite and not in real life, because three separate things all quietly assumed a cell has no size. `pty_spawn`/`pty_resize` left `ws_xpixel`/`ws_ypixel` zero, so a program asking the tty how big a cell is got nothing and guessed. `ghostty_terminal_resize` was called with `0, 0` for the cell size, so lib-vt could not work out how many cells an image covers when the placement did not say — and a placement that covers zero cells is dropped, which is a picture that silently does not appear. And the vendored lib freed image *data* on `ED 2`, so a full-screen program lost everything it had uploaded. The fix runs the whole way through: the client reads its terminal's pixel size (`TIOCGWINSZ`, re-read on every resize because a window can move to another monitor), `MSG_HELLO`/`MSG_RESIZE` carry it, the app hands it to every pane in every tab, and each pane gives it to both its pty and its terminal. Where nobody knows, the default is **8x16 rather than 0**: a plausible cell means an image appears at roughly the right size, and zero means it does not appear at all. Tested end to end, including that a program can read real pixel dimensions out of its own pty. **Re-emission has to preserve what the program meant, not what it currently covers.** Two things fall out of that. A placement carries a sub-cell offset (`X=`/`Y=`, where the image starts *inside* its first cell); dropping it is invisible in a still picture and makes anything moving jump a whole cell at a time. And `c=`/`r=` mean *scale into this many cells*, so they are passed on only when the program asked for them — sending the count a natural-size image happens to cover makes it change size as it slides across a cell boundary, because that count goes up by one. Cropping follows the same split: a natural image is cropped by the screen pixels the pane has left (measured from the offset, not the cell edge), a scaled one proportionally, because a lost cell is worth `source/cells` pixels there. **And a program may prefer to *ask*.** `TIOCGWINSZ`'s pixel fields are the first way to find the cell size and XTWINOPS (`CSI 14/16/18 t`) is the second, which is what a program reaches for when the pty fields come back zeroed — as they do on the far side of an ssh hop. We answered none of it, so the query timed out and the program fell back to a guess; 10x20 against a real 9x22 cell is every image stretched by a fifth, and it looks like a bug in the program. `GHOSTTY_TERMINAL_OPT_SIZE` answers all three from the pane's own geometry (lib-vt encodes the reply). Mode 2048, the in-band report on resize, already worked: it is answered from the size handed to `ghostty_terminal_resize`. | | **D18** | **We decode PNG ourselves, with the stb_image we already vendor.** lib-vt ships no image codec: built as a library its `sys.decode_png` hook is null, and a null hook rejects every `f=100` transmission outright — no image stored, no placement, nothing to re-emit. A program that uploads a PNG (which is what a program with a picture on disk does) drew nothing at all, silently, while raw RGB worked. Found because ida-tui's startup logo never appeared. PNG is the only format this can ever be about: the protocol has exactly three (`f=24`, `f=32`, `f=100`) and the first two are raw pixels lib-vt already handles, and `decode_png` is the only codec hook it has — so there is no scope to creep. Decoding only, never encoding; the client is handed RGBA. The decoder is `vendor/libghostty-vt/src/stb/stb_image.h`, which is **already in the tree and already pinned** by the vendor commit — upstream compiles that same header with the same `STBI_ONLY_PNG` for the same reason (`src/stb/stb.c` says so), it is simply not part of the `-Demit-lib-vt` build. So this is not a new dependency, it is a file we already ship finally being compiled, and `src/png.c` is a hook and a copy around it. Hand-rolling a subset decoder was considered and rejected: the bulk of a PNG decoder is a DEFLATE inflate, and "just the colour type ida-tui uses" breaks on the first palette PNG, which is what every png optimiser emits. That is a lot of new bounds-checked parsing, fed by whatever a pane decides to send, to replace a file already in the repo. Two consequences to know: we re-emit **decoded** pixels, so a 819KB logo goes to the client as 3.3MB of base64 (once per image, again after a reattach clears `sent`) — passing the original PNG through would be cheaper but lib-vt hands back only the decoded form; and lib-vt caps image storage at **10MB** in library builds, so images are bigger than they look. | | **D19** | **The finder and the command palette are one picker with a subject.** They are the same object — a modal, a query, a filtered list, one selection, the same keys and the same mouse rules — differing only in what fills the rows and what Enter does with one. Building the second as its own machine would have meant two of everything, and the pair would have drifted the way the pane title editor and a tab label editor would have if they had not been made one thing with a subject. So there is one `picker` state (`PICK_FINDER`/`PICK_PALETTE`), one draw, one key handler, and a `pick_row_t` of three columns that both fill: a dim left (a tab, a group), the thing itself, and a dim right (a purpose, the chord). Choosing goes through the row's own action string, so the keyboard and the mouse cannot take different paths to the same row. **The palette lists actions that are not bound to anything**, which the cheatsheet by design cannot — it is built from the binds, so an action with no key does not appear, and that is exactly the action you have no other way to reach. Where a binding does exist the palette shows it, so using the palette teaches the key that would have skipped it; where several exist it shows them all, because a config's binds add to the defaults rather than replacing them and naming only the first would hide the one the user chose. Two actions are left out: `literal-prefix`, which means "type this key" rather than "do this thing" and would send the prefix to a pane hidden behind the list, and `select-tab-N`, which is positional — a row saying "go to that tab" cannot say which. Running is by `action_t`, not by synthesising the keystroke that would have caused it: a palette that had to invent input to do its job would be lying to the rest of the program about what happened. | -| **D20** | **Chrome is a rect too, so it is a pass too.** `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 (D16), same chain order, one new word. It is one pass over the frame's *whole* rect with the contents punched out as a hole, not 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 is what keeps the two honest — a skipped cell is never visited, so a full-strength chrome tint cannot reach your text and a full-strength content tint cannot reach the border. The chains are stored separately rather than as a flag on each shader, because a pass *is* a chain and a rect, and because `shader_abi.h` has no business knowing where a session chose to run an effect. This 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. **Animation needs a clock**, so `app_next_deadline_ms` reports one while a chain that reads `t` ran over the last frame — derived from what was applied, like everything else about a frame, so a pulse hung off `dead` costs `anim_ms` while a pane is dead and nothing for the rest of the session. Without it a border froze the moment you stopped typing, which is the bug that makes an animated shader look broken rather than absent. A **`bell` pane state** and a **`since`** variable came with it, because "flash the border when a pane rings" needed both and neither existed: a bell had no state to hang a chain off, and `t` says what time it is rather than how long ago something happened, so a one-shot effect was not expressible at all. `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, but 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 (the frame clock stops with it). Shipped off by default — `bell_indicator`'s quiet mark stays the default, and an animated default would spend a frame clock on every session. **`channel="fg"|"bg"|"both"`** came from the first border flash actually being looked at: `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 by the shader: the cell's other colour is snapshotted before materialising and put back after, so it works for a built-in and a plugin alike, an unset colour goes back to *unset* rather than to our guess, and no shader grows an fg-only variant of itself. It is one byte tested once per pass, not per cell, and 0 means both so every shader built before it behaves as it did. | +| **D20** | **Chrome is a rect too, so it is a pass too.** `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 (D16), same chain order, one new word. It is one pass over the frame's *whole* rect with the contents punched out as a hole, not 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 is what keeps the two honest — a skipped cell is never visited, so a full-strength chrome tint cannot reach your text and a full-strength content tint cannot reach the border. The chains are stored separately rather than as a flag on each shader, because a pass *is* a chain and a rect, and because `shader_abi.h` has no business knowing where a session chose to run an effect. This 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. **Animation needs a clock**, so `app_next_deadline_ms` reports one while a chain that reads `t` ran over the last frame — derived from what was applied, like everything else about a frame, so a pulse hung off `dead` costs `anim_ms` while a pane is dead and nothing for the rest of the session. Without it a border froze the moment you stopped typing, which is the bug that makes an animated shader look broken rather than absent. A **`bell` pane state** and a **`since`** variable came with it, because "flash the border when a pane rings" needed both and neither existed: a bell had no state to hang a chain off, and `t` says what time it is rather than how long ago something happened, so a one-shot effect was not expressible at all. `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, but 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 (the frame clock stops with it). **Shipped on by default**: the compiled-in `bell` state is two tints in theme's `bell` colour whose amounts read `since` — on the frame, three full-strength blinks over the first 900ms and then a slow breathe; on the body, a quiet shimmer — one soft diagonal sheen gliding across, peak strength 95 against the blinks' 255, its colour softened halfway towards `default_fg` (light, not paint), its width breathing on a sine as it travels, gone within those same 900ms — so what you are reading is only touched, gently, while the announcement lasts. Derived after the theme block the way the scrolled wash is, so a theme moves the mark, the flash and the shimmer together. The original objection was that an animated default would spend a frame clock on every session, and the clock's own derivation is what answers it: `since` carries `EXPR_DEP_TIME`, so the `anim_ms` clock runs only while a rung, unanswered pane is actually on screen — an idle session pays nothing. It follows `bell_indicator false` off (that knob's promise is silent *and* invisible), and `states { bell { … } }` — including an empty one — replaces it like any state, tracked across includes like `scrolled`. **`channel="fg"|"bg"|"both"`** came from the first border flash actually being looked at: `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 by the shader: the cell's other colour is snapshotted before materialising and put back after, so it works for a built-in and a plugin alike, an unset colour goes back to *unset* rather than to our guess, and no shader grows an fg-only variant of itself. It is one byte tested once per pass, not per cell, and 0 means both so every shader built before it behaves as it did. | | **D21** | **A project is a directory; a workspace is the tab it occupies.** Two words because they are two things, and conflating them is how a session grows a second source of truth about what it is looking at. The directory is found rather than named: a `project_roots "~/dev" "~/work" depth=2` is scanned for subdirectories holding a `slosh.layout.kdl` — or a `.git`, which is the project that has not said what it needs yet, and without which `~/dev` with forty checkouts and three layout files is a picker with three rows. A directory that *is* a project is never descended into, so the walk stays off `node_modules` without anyone writing a rule about `node_modules`. **Identity is the tab's `purpose`**, `project:<name>.<hash8>` of the resolved path — the shape D3 already published — so there is no second field to disagree with it, membership is a string comparison, and a dumped session restores it for free because a dump already writes tab purposes and applying one already locks them (D8). Hashed on the *path* rather than the name, so two worktrees of one repo are two workspaces, which is what they are. A tab whose layout gave it a purpose of its own keeps it and is simply not a member: overwriting a declared purpose is the one thing D8 forbids, and the reply counts the ones it left alone rather than letting that be a surprise later. **Nothing watches the filesystem.** The list is derived when it is asked for — one `readdir` per root and two `stat`s per entry, forty checkouts for eighty-one syscalls next to the keystroke that asked — and an answer nobody remembered cannot be stale, which is a promise no watcher can make on a bind mount. The picker scans once as it opens, not per frame, because `draw_picker` asks for its rows every frame and a `readdir` per repaint is a filesystem walk at 120Hz. The one thing a scan cannot see is a project's layout file changing under a workspace that is already open, and that is deliberately not answered by re-applying it over running processes: `workspaces` reports the file's `mtime`, and drift is derivable outside without this session storing a byte. **Opening is idempotent** (`sl0ppi up`'s property, D3): the same request twice is one workspace, focused, and the answer says which branch it took so a caller never has to ask first. **Saving is the inverse, and it is the whole of onboarding.** `save-workspace` is `dump-layout` for one tab, relative to the project, written beside it — the same dumper, so there is one answer to "what does this tab look like written down". Four things made that possible and none of them were true before: a relative `cwd=` in a layout file now resolves against that file's directory (the rule `include` already followed, applied to the other half of the same syntax), a dump can be asked for one tab against a base, a pane from a split now starts where the pane it came out of stands rather than where the server was launched — which had been quietly writing an absolute path to somebody else's directory into every saved project — and **a dump now records what a pane is actually running**. That last one is what turns arranging a project and writing it down into one act instead of two: `label` only ever knew what a *layout* said, so a pane you split and typed `npm run dev` into had nothing to say for itself and came back as a bare shell. The kernel knows what the label does not — a pty has a foreground process group, and that group is by definition the job that owns the terminal — so the answer is read rather than guessed, the way `live_cwd` already reads `/proc/PID/cwd` rather than trusting where a pane was started. Three things are deliberately not commands: a shell at a prompt (its group is the pane's own, and `command="zsh"` on every idle pane restores a session where each shell runs inside a shell), a background job (it does not own the terminal, and resurrecting `&` jobs in the foreground describes a session nobody had), and an ephemeral pane (restoring one reopens a file somebody finished with). A declared label still outranks a live process, because it survives the program exiting (D14) and re-saving must not degrade `npm run dev` into whatever the process tree looks like this minute. argv is joined with shell quoting, since `command=` is run through `/bin/sh -c` and an argument with a space in it would otherwise come back as two. A saved project defaults to `suspend="commands"`: the pane running this morning's dev server is written asleep, because a *project's* layout is a statement of shape and a *session's* dump is a statement of fact, and starting a dev server on every open is exactly what `suspended` exists to prevent — which is worth much more now that there are commands to suspend. What is **not** built: no guessing commands from `package.json` or `Cargo.toml` (a table of guesses that is wrong on day one and stale by year two — recording what you actually ran makes it unnecessary), no watcher, and no auto-save on close, because a layout file is a commit-sized decision. | ### D6 — responsive layout as a pure function @@ -21,7 +21,7 @@ VERSION := 0.1.0 GITDESC := $(shell git describe --always --dirty 2>/dev/null || echo unknown) CFLAGS := -std=c23 -O1 -g -Wall -Wextra -Wno-unused-parameter -MMD -MP \ - -I$(VT_INC) -Isrc -Ibuild + -I$(VT_INC) -Iinclude -Ibuild LDFLAGS := SRC := $(wildcard src/*.c) @@ -130,17 +130,17 @@ $(SHADER_TEST): tests/shader_test.c src/shader.c src/screen.c src/json.c src/exp # Shader plugins, for test_shader_plugin.py: a good one, one that announces an # ABI we do not speak, and the example we ship in contrib -- which is built # here so that a broken example is a failing test rather than a bug report. -PLUGIN_CFLAGS := -std=c23 -O1 -fPIC -shared -Isrc +PLUGIN_CFLAGS := -std=c23 -O1 -fPIC -shared -Iinclude -build/testshader.so: tests/shader_plugin_test.c src/shader_abi.h | build +build/testshader.so: tests/shader_plugin_test.c include/shader_abi.h | build $(call say,[SO],$@) $(Q)$(CC) $(PLUGIN_CFLAGS) $< -o $@ -build/badshader.so: tests/shader_plugin_test.c src/shader_abi.h | build +build/badshader.so: tests/shader_plugin_test.c include/shader_abi.h | build $(call say,[SO],$@) $(Q)$(CC) $(PLUGIN_CFLAGS) -DBAD_ABI $< -o $@ -build/exampleshader.so: contrib/shader-plugin/example.c src/shader_abi.h | build +build/exampleshader.so: contrib/shader-plugin/example.c include/shader_abi.h | build $(call say,[SO],$@) $(Q)$(CC) $(PLUGIN_CFLAGS) $< -o $@ @@ -196,7 +196,7 @@ COV_DIR := build/cov COV_SRC := $(wildcard src/*.c) COV_OBJ := $(COV_SRC:src/%.c=$(COV_DIR)/%.o) COV_CC ?= gcc -COV_FLAGS := -std=c23 -O0 -g --coverage -I$(VT_INC) -Isrc -Ibuild +COV_FLAGS := -std=c23 -O0 -g --coverage -I$(VT_INC) -Iinclude -Ibuild $(COV_DIR)/%.o: src/%.c build/version.h | $(COV_DIR) $(call say,[COV],$<) @@ -249,7 +249,8 @@ coverage: $(COV_DIR)/slosh $(COV_UNITS) ## how much of the code the tests run # scripts are Python with no extension, so they are named rather than globbed. CSRC := $(shell git ls-files '*.c' '*.h' 2>/dev/null | grep -v '^vendor/') PYSRC := $(shell git ls-files '*.py' 2>/dev/null | grep -v '^vendor/') \ - contrib/coverage contrib/gen-docs contrib/shader-repl + contrib/coverage contrib/gen-docs contrib/shader-repl \ + contrib/webdemo/boot-check contrib/webdemo/build-rootfs contrib/webdemo/serve # clang-format is a system package. ruff usually is not, and `pip install --user` # is refused outright on a distro python (PEP 668), so `make tools` puts it in a diff --git a/config/config.kdl b/config/config.kdl index 2bb356a..85f9447 100644 --- a/config/config.kdl +++ b/config/config.kdl @@ -39,7 +39,7 @@ // // A config can be made of files: // -// include "themes/amber.kdl" // contrib/themes has six +// include "themes/amber.kdl" // contrib/themes has seven // include "keys/vim.kdl" "shaders/crt.kdl" // // which is how you switch a theme by editing one line instead of pasting one. @@ -115,10 +115,27 @@ title_inset 2 // is what puts it out. Off makes a bell silent *and* invisible, which is a // real choice rather than an oversight. // -// The mark is the quiet default. A louder one is a shader rather than a knob: -// `bell` is a pane state, so `states { bell { ... } }` colours or flashes a -// rung pane's frame for as long as the bell is unanswered. See the chrome -// passes further down. +// The mark is one cell wide, which is not news you can see from the corner of +// your eye -- so by default the pane says it too, in theme's `bell` colour. +// The *frame*: three sharp blinks the moment it rings, then a slow breathe +// until it is answered. The *body*: a shimmer -- one soft diagonal sheen +// gliding across, the way light crosses something glossy, gone within the +// same 900ms the blinks take. It is quiet on purpose: peak 95 where the +// blinks are 255, its colour softened halfway towards default_fg so it reads +// as light rather than paint, and its width breathing on a sine as it +// travels. Motion is what pulls the eye, not brightness, so it draws you to +// the pane without shouting over what it says. Both are derived, like +// the scrolled wash: built from the theme after the theme is read, so a theme +// moves the mark, the flash and the shimmer together, and they are commented +// out in the states block below for the same reason scrolled is. Both read +// `since`, so the frame clock they cost runs only while a rung pane is +// actually on screen. +// +// Turning it off is either of the things it hangs from: `bell_indicator +// false` silences the bell everywhere (mark and flash -- that is what +// invisible means), and `states { bell { } }` removes just the flash. A +// `bell { ... }` chain of your own replaces it outright, like every state -- +// the chrome passes further down have a few worth stealing. // ── the frame's own buttons ───────────────────────────────────────────────── // // Minimise, zoom and close, in the top-right of every pane's frame: the mark @@ -254,7 +271,7 @@ focus_follows_mouse true // Whether the program running in a pane may set that pane's shader chains, by // printing an escape sequence: // -// printf '\033]5577;1;shader;chrome;tint color="#ff5fd7" amount=255\033\\' +// printf '\033]5577;1;shader;chrome;tint color="#7aa2f7" amount=255\033\\' // // The payload after `chrome` (or `content`) is a chain in exactly the syntax the // `shaders` block below uses, so a chain you arrive at this way is a line you can @@ -414,10 +431,12 @@ modal_scrim 120 // ── shaders ───────────────────────────────────────────────────────────────── // -// Colour passes over a pane's contents (never the frame, title or tab strip). -// Both are strengths from 0 to 255, where 0 is off and 255 is fully applied. -// Both resolve default-coloured text through theme's default_fg/default_bg, -// so set those to your terminal's real colours or a shaded pane will shift. +// Colour passes over a pane's contents by default; `where="chrome"` aims one +// at the frame instead (see the chrome passes further down), and the tab +// strip and status line are never shaded. Strengths run 0 to 255, where 0 is +// off and 255 is fully applied, and a pass resolves default-coloured text +// through theme's default_fg/default_bg -- set those to your terminal's real +// colours or a shaded pane will shift. // What a pane looks like while it is in a particular state. Each state takes // the same chain of passes `shaders` does. @@ -452,6 +471,12 @@ modal_scrim 120 // the past. None of that is discoverable by looking unless something says // so, which is the entire argument for colouring it. // +// a pane that is *news* gets one too -- bell. A ring is an event rather +// than a condition, so its default moves: a shimmer across the body that is +// gone within a second, and blinks then a breathe on the frame -- the one +// chrome pass in this table -- in theme's bell colour (see the bell section +// above, and `bell_indicator false` to silence it with the mark). +// // a pane that is merely *not the one you are in* is a taste rather than a // fact, and gets a default anyway -- but through `dim_unfocused` above, // which is one number to change or zero out. The objection to shipping a @@ -460,19 +485,33 @@ modal_scrim 120 // your hand keeping its colour is what makes it lift off the page. // // All the defaults are gentle: a dead pane, a suspended one and scrollback are -// all things you still want to read. The compiled-in scrolled tint uses the -// scrollback indicator's own colour (theme's scroll_bg) so a theme moves both -// together; written here it is spelled out, because a `color=` you do not give -// falls back to theme's frame_focus, which is a different setting that happens -// to hold the same value in every theme we ship. +// all things you still want to read. The scrolled default is *derived*, not +// stored, and has two parts. The wash: the scrollback indicator's own colour +// (theme's scroll_bg), worked out after the theme is read, so a theme moves +// the wash and the indicator together. The edge fades: the viewport's top and +// bottom rows melt towards the edge, the way a scrollable list fades where it +// continues -- and each fade exists only while there is content past that +// edge, so hitting the top of the buffer turns the top edge solid, and +// returning to the present ends the state and everything is opaque again. Up +// to three rows a side, never more than a quarter of the viewport each. All +// of it is commented below because naming a state replaces its default +// outright -- a declared copy would pin the wash to one theme's colour and +// quietly stop following the next. states { drop_hover { grayscale amount=200; dim amount=140 } drop_target { grayscale amount=200; dim amount=140 } dead { grayscale amount=200; dim amount=90 } suspended { grayscale amount=170; dim amount=60 } - scrolled { tint amount=22 color="#ff5fd7" } // = theme's scroll_bg + // scrolled { // derived: a wash of theme's scroll_bg, and edge fades where more content is + // tint amount=22 color="#7aa2f7" + // dim amount="(above > 0) * max(0, (min(3, rows / 4) - y) * 45)" + // dim amount="(below > 0) * max(0, (y - rows + min(3, rows / 4) + 1) * 45)" + // } // dragging { } - // bell { } // see the chrome passes below for a border flash + // bell { // derived: a body shimmer, and a frame blink-then-breathe, in theme's bell colour + // tint color="#efd7b3" amount="(since < 900) * max(0, 95 - abs(x + 2 * y - since / 4) * (6 + sin(since / 2) / 96) - since / 64)" + // tint where="chrome" channel="fg" color="#e0af68" amount="since < 900 ? (since / 150 % 2 == 0) * 255 : 120 + sin(since / 8 + 158) / 3" + // } // unfocused { dim amount=60 } // = dim_unfocused above; yours replaces it } @@ -513,7 +552,7 @@ states { // shaders { // dim amount="(y % 2) * 40" // scanlines // dim amount="(x > cols - 10) * 120" // the right margin -// tint amount="255 - dist(x, y, curx, cury) * 12" color="#ff5fd7" +// tint amount="255 - dist(x, y, curx, cury) * 12" color="#7aa2f7" // } // // The expression produces the *strength*, never the colour: the mixing stays @@ -529,6 +568,12 @@ states { // this pane has it // focused 0 or 1 // t milliseconds, for animation +// since milliseconds the pane has been in its current +// state -- what a one-shot effect needs, because +// `t` is the time, not how long ago +// above below lines of scrollback hidden past the viewport's +// top and bottom edges, both 0 at the present -- +// what lets an effect say "there is more this way" // operators + - * / % integer only; division by zero is 0, not a crash // < > <= >= == != and && || !, which give 0 or 1 -- so // `(x < 10) * 200` is how you write a rule @@ -569,7 +614,7 @@ states { // shaders { // vignette amount=70 // zebra amount=22 -// ruler amount=60 at=80 color="#ff5fd7" +// ruler amount=60 at=80 color="#7aa2f7" // spotlight amount=90 radius=14 // } @@ -599,7 +644,7 @@ states { // // shaders { // // the top rule only, where the title is -// tint where="chrome" channel="fg" color="#ff5fd7" amount="(y==0)*255" +// tint where="chrome" channel="fg" color="#7aa2f7" amount="(y==0)*255" // // a corner glow. One node per line: a newline ends a node, so a // // pass split over two lines is two broken nodes, not one pass. // tint where="chrome" channel="fg" color="#00ffd7" amount="255-dist(x,y,0,0)*20" @@ -618,9 +663,9 @@ states { // `(p - head + P) % P` is "how far ahead of the head", which makes an arc // rotate rather than a blob slide. There is no way to name a subexpression, so // it has to be written out in full -- which is why a small effect is a long -// line. contrib/chrome has seven of them ready to paste (a shine running round -// the border, sparkles, ripples from a corner, a rotating arc, a static -// gradient, corner glints, a sheen across the title rule). +// line. contrib/chrome has a dozen-odd ready to paste -- a shine running +// round the border, ripples from a corner, a rotating comet, corner glints, a +// sheen across the title rule, and more; the directory is the list. // // Hung off a state, this is a border that says what a pane is doing -- which // is what chrome is for, and it costs no room and no text: @@ -632,7 +677,8 @@ states { // // a bell nobody has answered yet: `since` is how long the pane has // // been in this state, so this is a real *flash* -- full strength for // // a quarter second and then gone, without the bell being answered. -// // `t` could not say that: it is the time, not how long ago. +// // `t` could not say that: it is the time, not how long ago. (The +// // default bell flash is this idea grown up: blinks, then a breathe.) // bell { tint where="chrome" channel="fg" color="#ffcc00" amount="(since<250)*255" } // // one that has not started yet is outlined, not filled // suspended { tint where="chrome" channel="fg" color="#8a8a95" amount=160 } @@ -648,10 +694,13 @@ states { // all the way through, so a chrome pass is the only kind that can still colour // it -- which is the state where a colour is worth the most. // -// Empty by default, like the content passes: yours to ask for. +// The global chain is empty by default, like the content passes: yours to ask +// for. One chrome pass does ship, hung off a state rather than here: the bell +// flash (see the bell section, and the states table above). // How often to repaint while a shader is animated, in milliseconds -- which -// means one whose `amount` reads `t`. Nothing else needs a frame clock: every +// means one whose `amount` reads `t` or `since`. Nothing else needs a frame +// clock: every // other repaint has an event behind it, and this one is only asked for while // such a shader is actually on screen. 0 turns it off, which leaves an // animated shader advancing only when something else causes a frame. @@ -678,28 +727,28 @@ theme { default_bg "#000000" // ── panes ─────────────────────────────────────────────────────────────── - frame_focus "#ff5fd7" // border of the focused pane + frame_focus "#7aa2f7" // border of the focused pane frame_idle "#45454a" // border of every other pane title "#ffffff" // its title, and its OSC 5577 status text title_idle "#45454a" // the same, on a pane that is not focused // A pane's own OSC 5577 buttons. button_fg "#141418" - button_bg "#ff5fd7" + button_bg "#7aa2f7" button_bg_idle "#55555c" // buttons on a pane that is not focused // ── things that appear under the pointer ──────────────────────────────── - guide "#ff5fd7" // split guide: armed edge, handle, its arrow, boundary - resize "#ff5fd7" // the handle in the gap between two panes - drop_target "#ff5fd7" // frame of a pane a drag could land on + guide "#7aa2f7" // split guide: armed edge, handle, its arrow, boundary + resize "#7aa2f7" // the handle in the gap between two panes + drop_target "#7aa2f7" // frame of a pane a drag could land on // ── a pane's scrollback indicator ─────────────────────────────────────── scroll_fg "#141418" - scroll_bg "#ff5fd7" + scroll_bg "#7aa2f7" // ── rows of a tab that has collapsed into a list ──────────────────────── header "#45454a" - header_hover "#ff5fd7" // the rule, under the pointer + header_hover "#7aa2f7" // the rule, under the pointer header_hover_title "#ffffff" // the name, under the pointer // ── the strip along the top ───────────────────────────────────────────── @@ -708,12 +757,12 @@ theme { // is on it -- it is still the tab you are in -- so its hover lands on the // text instead. tab_active_fg "#141418" - tab_active_bg "#ff5fd7" + tab_active_bg "#7aa2f7" tab_active_hover_fg "#ffffff" tab_idle "#45454a" - tab_hover "#ff5fd7" + tab_hover "#7aa2f7" prefix_fg "#141418" // the "C-a" badge, while the prefix is pending - prefix_bg "#ff5fd7" + prefix_bg "#7aa2f7" tab_count "#45454a" // panes in the whole session // ── the line along the bottom ─────────────────────────────────────────── @@ -722,15 +771,16 @@ theme { hint "#ffffff" // what the pointer is on, in the middle // ── marks on a pane's frame ───────────────────────────────────────────── - bell "#ff5fd7" // a pane rang and has not been looked at + bell "#e0af68" // a pane rang and has not been looked at: + // amber, not the accent -- attention, not focus dead "#ff875f" // its program exited: the line in its backlog, // and the words in its frame and the status line pane_button "#45454a" // the frame's own close/zoom/minimise marks - pane_button_hover "#ff5fd7" + pane_button_hover "#7aa2f7" // ── the row of minimised panes ────────────────────────────────────────── minbar "#45454a" - minbar_hover "#ff5fd7" + minbar_hover "#7aa2f7" // ── modals: a surface that floats over the layout ─────────────────────── // Named apart from the pane colours they resemble because a modal is a @@ -740,10 +790,10 @@ theme { // which are the same value — an invisible button until you hovered it.) modal_bg "#1c1c22" // a shade lighter than the dimmed screen modal_fg "#e8e8ea" - modal_border "#ff5fd7" + modal_border "#7aa2f7" modal_title "#ffffff" modal_button "#8a8a95" // visible *without* the pointer on it - modal_button_hover "#ff5fd7" + modal_button_hover "#7aa2f7" // ── the pane finder ───────────────────────────────────────────────────── // The finder is a modal, so its box is the modal colours above; these are @@ -753,15 +803,15 @@ theme { finder_fg "#ffffff" finder_bg "#45454a" finder_sel_fg "#141418" - finder_sel_bg "#ff5fd7" // the row enter would take + finder_sel_bg "#7aa2f7" // the row enter would take // ── the in-place editor a double-click opens on a pane title ──────────── rename_fg "#141418" - rename_bg "#ff5fd7" + rename_bg "#7aa2f7" // ── announcements ─────────────────────────────────────────────────────── toast_fg "#141418" - toast_bg "#ff5fd7" + toast_bg "#7aa2f7" } // ── keys ──────────────────────────────────────────────────────────────────── diff --git a/contrib/README.md b/contrib/README.md index c932199..5809694 100644 --- a/contrib/README.md +++ b/contrib/README.md @@ -4,13 +4,14 @@ Things that are useful but are not the multiplexer. ## themes/ -Six complete themes. Each sets **every** colour the config knows about, so +Seven complete themes. Each sets **every** colour the config knows about, so nothing silently falls back to a compiled-in default that belongs to a different palette — there is a test that keeps them that way. | | | |---|---| -| `sl0p` | the default: hot pink on near-black | +| `default` | what no config gets you: muted blue on neutral dark | +| `sl0p` | the house style: hot pink on near-black | | `phosphor` | a green CRT that never quite went away | | `amber` | the other CRT, for people who found green loud | | `slate` | muted blues, for looking at all day | @@ -99,7 +100,7 @@ A skeleton for adding your own shaders as a shared library, with a Makefile and two worked examples (`checker`, `pulse`). Build it, drop the `.so` in `~/.config/slosh/shaders/`, and name it in your config like a built-in. -The only header a plugin needs is `src/shader_abi.h`. What a shader may and +The only header a plugin needs is `include/shader_abi.h`. What a shader may and may not do — and why a plugin is native code rather than a sandboxed one — is in that directory's README. @@ -135,6 +136,21 @@ that computes zero everywhere, because an example that does nothing reads as a broken shader system rather than a bad example. It found its first bug on its first run. +## webdemo/ + +slosh in a browser tab, for people who want to try it without installing it: +a riscv64 Linux booted by Bellard's TinyEMU compiled to WebAssembly, an Alpine +userland we build into a disk image, and slosh as the thing you land in. + +```sh +cd contrib/webdemo && make && make serve +``` + +The output is static files, so it can be served from anywhere that can serve a +directory. `make check` boots the same image in a native emulator and asserts +the session comes up, which is how a change to the guest is tested without +opening a browser at all. + ## coverage ```sh diff --git a/contrib/shader-plugin/Makefile b/contrib/shader-plugin/Makefile index 1240c85..1a0fb5d 100644 --- a/contrib/shader-plugin/Makefile +++ b/contrib/shader-plugin/Makefile @@ -1,22 +1,25 @@ # Build a slosh shader plugin. # -# The only thing a plugin needs is src/shader_abi.h. Any C compiler will do — +# The only thing a plugin needs is include/shader_abi.h. Any C compiler will do — # zig is used here because the project already depends on it, not because it # has to be. Out of tree, copy shader_abi.h next to your source and drop the # -I below. -SLOSH ?= ../.. +# Not `SLOSH ?=`: slosh itself exports SLOSH=1 into every pane it runs (the +# way tmux exports TMUX), so building *from inside a session* -- the normal +# case -- would read that as the path. +SLOSH_DIR ?= ../.. ZIG ?= $(HOME)/zig-0.16.0/zig CC ?= $(ZIG) cc -CFLAGS := -std=c23 -O2 -Wall -Wextra -fPIC -I$(SLOSH)/src +CFLAGS := -std=c23 -O2 -Wall -Wextra -fPIC -I$(SLOSH_DIR)/include PREFIX ?= $(HOME)/.config/slosh/shaders .PHONY: all install clean all: example.so ## build the plugin -example.so: example.c $(SLOSH)/src/shader_abi.h +example.so: example.c $(SLOSH_DIR)/include/shader_abi.h $(CC) $(CFLAGS) -shared $< -o $@ install: example.so ## copy it where slosh looks diff --git a/contrib/shader-plugin/README.md b/contrib/shader-plugin/README.md index 6c5150a..d8ee7e3 100644 --- a/contrib/shader-plugin/README.md +++ b/contrib/shader-plugin/README.md @@ -30,7 +30,7 @@ a plugin, restart the session. ## Writing one -Everything you need is in [`src/shader_abi.h`](../../src/shader_abi.h) — one +Everything you need is in [`include/shader_abi.h`](../../include/shader_abi.h) — one header, no libghostty-vt, no other slosh types. `example.c` is a working plugin with two effects and comments about what each one demonstrates. diff --git a/contrib/shader-repl b/contrib/shader-repl index 72df0be..c0ff216 100755 --- a/contrib/shader-repl +++ b/contrib/shader-repl @@ -123,7 +123,20 @@ PROPS = [ ] # Values worth offering: the two rects, the three channels. VALUES = ['"chrome"', '"content"', '"fg"', '"bg"', '"both"'] -VARS = ["x", "y", "cols", "rows", "curx", "cury", "cursor", "focused", "t", "since"] +VARS = [ + "x", + "y", + "cols", + "rows", + "curx", + "cury", + "cursor", + "focused", + "t", + "since", + "above", + "below", +] # Angles are degrees, so pi is a half turn: `PI` is 180 and `TAU` is 360. CONSTS = ["PI", "TAU"] FUNCS = ["min(", "max(", "abs(", "clamp(", "dist(", "sin(", "cos("] diff --git a/contrib/themes/default.kdl b/contrib/themes/default.kdl new file mode 100644 index 0000000..0d8f7a8 --- /dev/null +++ b/contrib/themes/default.kdl @@ -0,0 +1,81 @@ +// default -- what no config gets you: muted blue on neutral dark +// +// This file exists so the tour can show the starting point and so another +// theme is one include-swap away from coming back. It matches the compiled-in +// palette exactly (`slosh --dump-config` is the authority if they ever drift). +// +// Two colours mean something rather than match something: `bell` is amber +// (attention, not focus) and `dead` is warm red-orange. Everything else that +// says "this one" -- the focused frame, the guide, the active tab -- is one +// muted blue, calm enough to frame text without shouting over it. +theme { + // what a shader takes "terminal default" to mean + default_fg "#ffffff" + default_bg "#000000" + + // panes + frame_focus "#7aa2f7" + frame_idle "#45454a" + title "#ffffff" + title_idle "#45454a" + + // a pane's own OSC 5577 buttons + button_fg "#141418" + button_bg "#7aa2f7" + button_bg_idle "#55555c" + + // affordances under the pointer + guide "#7aa2f7" + resize "#7aa2f7" + drop_target "#7aa2f7" + + // scrollback indicator + scroll_fg "#141418" + scroll_bg "#7aa2f7" + + // rows of a tab collapsed into a list + header "#45454a" + header_hover "#7aa2f7" + header_hover_title "#ffffff" + + // the strip along the top + tab_active_fg "#141418" + tab_active_bg "#7aa2f7" + tab_active_hover_fg "#ffffff" + tab_idle "#45454a" + tab_hover "#7aa2f7" + prefix_fg "#141418" + prefix_bg "#7aa2f7" + tab_count "#45454a" + + // the line along the bottom + status "#45454a" + status_state "#ffffff" + hint "#ffffff" + + // the pane finder + finder_fg "#ffffff" + finder_bg "#45454a" + finder_sel_fg "#141418" + finder_sel_bg "#7aa2f7" + + // rename editor, bell, dead panes, frame buttons, the minimised bar + rename_fg "#141418" + rename_bg "#7aa2f7" + toast_fg "#141418" + toast_bg "#7aa2f7" + bell "#e0af68" + dead "#ff875f" + pane_button "#45454a" + pane_button_hover "#7aa2f7" + minbar "#45454a" + minbar_hover "#7aa2f7" + + // a modal floating over the layout (the cheatsheet, C-a ?) + modal_bg "#1c1c22" + modal_fg "#e8e8ea" + modal_border "#7aa2f7" + modal_title "#ffffff" + modal_button "#8a8a95" + modal_button_hover "#7aa2f7" +} diff --git a/contrib/themes/sl0p.kdl b/contrib/themes/sl0p.kdl index cc13f89..680f166 100644 --- a/contrib/themes/sl0p.kdl +++ b/contrib/themes/sl0p.kdl @@ -1,4 +1,4 @@ -// sl0p -- the default: hot pink on near-black +// sl0p -- the house style: hot pink on near-black // // Drop into ~/.config/slosh/config.kdl, or point $SLOSH_CONFIG at a file // that contains it. A running session re-reads it the moment you save. @@ -16,7 +16,7 @@ theme { // a pane's own OSC 5577 buttons button_fg "#141418" button_bg "#ff5fd7" - button_bg_idle "#45454a" + button_bg_idle "#55555c" // affordances under the pointer guide "#ff5fd7" diff --git a/docs/chrome.md b/docs/chrome.md index a348fcc..5262b18 100644 --- a/docs/chrome.md +++ b/docs/chrome.md @@ -15,6 +15,13 @@ Nothing else changes: same shaders, same `amount`, same [expressions](shaders.md#strength-as-an-expression), same chain order. One new word. +You have already seen one: the default bell flash — blinks then a breathe on +the frame of a pane that rang, in theme's `bell` colour — is exactly this, a +chrome tint whose amount reads `since`. (The shimmer that crosses the pane's +body at the same moment is the same idea without the new word: an ordinary +content pass in the same chain.) Writing your own `bell { … }` replaces both; +`bell_indicator false` silences them with the mark. + ## Two rules **`channel="fg"`, almost always.** A border's *background* is the terminal's own diff --git a/docs/config.md b/docs/config.md index c9578ac..686ef0e 100644 --- a/docs/config.md +++ b/docs/config.md @@ -182,8 +182,15 @@ dim_unfocused 60 // the one knob most people want states { // ...and the whole table underneath it dead { grayscale amount=200; dim amount=90 } suspended { grayscale amount=170; dim amount=60 } - scrolled { tint amount=22 color="#ff5fd7" } + scrolled { tint amount=22 color="#7aa2f7" } // follows theme's scroll_bg; + // plus derived edge fades: the top and bottom rows melt towards an edge + // while there is more content past it (`above` / `below` in expressions), + // and turn solid at the end of the buffer -- nothing more to scroll to unfocused { dim amount=60 } // writing this replaces dim_unfocused + // bell: a shimmer across the body (a soft sheen, gone within a second) + // and a chrome pass on the frame -- blinks, then a breathe -- in theme's + // bell colour, until the pane is looked at. See the chrome shaders page; + // an empty bell { } removes it, bell_indicator false silences bell + mark. } ``` diff --git a/docs/shaders.md b/docs/shaders.md index 860ad24..b3c1cc1 100644 --- a/docs/shaders.md +++ b/docs/shaders.md @@ -12,7 +12,7 @@ touched, because rewriting text would desync selection and copy. ```kdl shaders { // every pane gets these, in the order written vignette amount=70 - ruler amount=60 at=80 color="#ff5fd7" + ruler amount=60 at=80 color="#7aa2f7" } ``` @@ -47,7 +47,7 @@ That is how you get an effect nobody built in, without building anything: shaders { dim amount="(y % 2) * 40" // scanlines dim amount="(x > cols - 10) * 120" // a right margin - tint amount="255 - dist(x, y, curx, cury) * 12" color="#ff5fd7" + tint amount="255 - dist(x, y, curx, cury) * 12" color="#7aa2f7" } ``` @@ -59,6 +59,7 @@ shaders { | | `focused` — 0 or 1 | | | `t` — milliseconds, for animation | | | `since` — milliseconds the pane has been in its current state | +| | `above` `below` — lines of scrollback hidden past the viewport's top and bottom edges, both 0 at the present | | operators | `+ - * / %` (integer; division by zero is 0, not a crash) | | | `< > <= >= == != && \|\| !` give 0 or 1, so `(x < 10) * 200` is a rule | | | `& \| ^ ~ << >>` on the 32-bit value, binding **tighter** than comparison — so `x & 7 == 0` asks what it looks like, unlike C | @@ -105,7 +106,7 @@ Edit, save, look, guess again is a slow way to arrive at a colour. A program can 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;chrome;tint color="#7aa2f7" amount="abs(t / 8 %% 510 - 255)"\033\\' printf '\033]5577;1;shader;content;dim amount=90\033\\' 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 diff --git a/src/app.h b/include/app.h index 2a3435e..2a3435e 100644 --- a/src/app.h +++ b/include/app.h diff --git a/src/cmd.h b/include/cmd.h index a54505d..a54505d 100644 --- a/src/cmd.h +++ b/include/cmd.h diff --git a/src/config.h b/include/config.h index a8b94f5..ce4d5b0 100644 --- a/src/config.h +++ b/include/config.h @@ -237,6 +237,16 @@ typedef struct { shader_t state_shaders[PSTATE_COUNT][SHADE_MAX]; size_t state_n[PSTATE_COUNT]; + /* Whether any file in this load named `scrolled` (or `bell`) itself. The + * default wash over scrollback and the default bell flash are derived from + * the theme *after* each file's theme block -- scroll_bg and bell + * respectively -- so a theme moves them with their indicators. But a chain + * somebody wrote, in this file or in one it included, must stand. A local + * flag cannot say that across an include chain, so they live here and are + * cleared with the rest of the defaults. */ + bool scrolled_declared; + bool bell_declared; + /* The same two things again, over a pane's *frame* rather than its contents: * any entry in `shaders` or in a state's block carrying `where="chrome"` * lands here instead. Separate chains rather than a flag on each shader, diff --git a/src/expr.h b/include/expr.h index c409ded..d593319 100644 --- a/src/expr.h +++ b/include/expr.h @@ -20,7 +20,7 @@ * nothing in here has an effect. Evaluation is therefore O(program length), * a bad expression cannot hang a session, and there is nothing to sandbox. * - * variables x y cols rows curx cury cursor focused t since + * variables x y cols rows curx cury cursor focused t since above below * operators + - * / % < > <= >= == != && || ! ?: * functions min max abs clamp dist * @@ -28,8 +28,10 @@ * contents, or its frame for a chrome pass), `t` is a millisecond clock for * animation, `since` is how many milliseconds the pane has been in the state * it is in — which is what a one-shot effect needs, because `t` says what time - * it is and not how long ago something happened. `dist` corrects for a cell - * being about twice as tall as it is wide. Division and modulo by zero are 0 + * it is and not how long ago something happened. `above`/`below` are the lines + * of scrollback hidden past the viewport's top and bottom edges, both 0 at + * the present — which is what lets an effect say "there is more this way". + * `dist` corrects for a cell being about twice as tall as it is wide. Division and modulo by zero are 0 * rather than a trap: an expression that is wrong should look wrong, not take * the session with it. */ @@ -55,6 +57,7 @@ enum { * dependency, or a program reading only the size would look constant and be * folded at compile time, where the size is not known yet and is zero. */ EXPR_DEP_SIZE = 1 << 4, + EXPR_DEP_SCROLL = 1 << 5, /* above, below */ }; /* Compile, or NULL with a reason in `err`. A program that reads nothing is @@ -76,12 +79,20 @@ typedef struct { int64_t t; /* Milliseconds since the pane entered its current state, clamped at 0. */ int64_t since; + /* Lines of scrollback hidden above and below the viewport, both 0 at the + * present (and for a pass over anything that is not a pane's contents). */ + int above, below; } expr_env_t; /* Evaluate for one cell. Clamped to 0..255 by the caller, not here: the * language has no opinion about what its number is for. */ int expr_eval(const expr_prog_t *p, const expr_env_t *env); +/* The text this program was compiled from, owned by the program. For the + * config dump, which has to write back the line somebody wrote rather than + * pretend an expression was a number. */ +const char *expr_source(const expr_prog_t *p); + /* Evaluate for every cell of a cols x rows rect into `out` (cols*rows bytes, * clamped to 0..255), reusing the last result when nothing it reads has * changed. Returns false when the program reads the clock, which is the one diff --git a/src/graphics.h b/include/graphics.h index b3cd6ec..b3cd6ec 100644 --- a/src/graphics.h +++ b/include/graphics.h diff --git a/src/input.h b/include/input.h index adda27a..adda27a 100644 --- a/src/input.h +++ b/include/input.h diff --git a/src/json.h b/include/json.h index f9442ad..f9442ad 100644 --- a/src/json.h +++ b/include/json.h diff --git a/src/jsonval.h b/include/jsonval.h index 1eedb4c..1eedb4c 100644 --- a/src/jsonval.h +++ b/include/jsonval.h diff --git a/src/kdl.h b/include/kdl.h index 9787fd9..9787fd9 100644 --- a/src/kdl.h +++ b/include/kdl.h diff --git a/src/osc5577.h b/include/osc5577.h index e6033f1..e6033f1 100644 --- a/src/osc5577.h +++ b/include/osc5577.h diff --git a/src/png.h b/include/png.h index ddd1b72..ddd1b72 100644 --- a/src/png.h +++ b/include/png.h diff --git a/src/project.h b/include/project.h index 6bf3021..6bf3021 100644 --- a/src/project.h +++ b/include/project.h diff --git a/src/proto.h b/include/proto.h index e6cd42c..e6cd42c 100644 --- a/src/proto.h +++ b/include/proto.h diff --git a/src/server.h b/include/server.h index b5d114a..b5d114a 100644 --- a/src/server.h +++ b/include/server.h diff --git a/src/shader.h b/include/shader.h index a6d9f65..a6d9f65 100644 --- a/src/shader.h +++ b/include/shader.h diff --git a/src/shader_abi.h b/include/shader_abi.h index be737c4..8c7a129 100644 --- a/src/shader_abi.h +++ b/include/shader_abi.h @@ -21,7 +21,7 @@ /* 3: shade_ctx_t gained `state_ms`, so an effect can know how long the pane has * been as it is and not only what time it is; struct shader gained * `channels`, which is the pass's business rather than a shader's. */ -#define SLOSH_SHADER_ABI 3 +#define SLOSH_SHADER_ABI 4 /* Which of a cell's two colours a pass is allowed to keep. Enforced by the * pass, not by the shader: every shader writes whatever it writes, and the @@ -88,6 +88,11 @@ typedef struct { bool has_cursor; uint16_t cursor_x, cursor_y; + /* Scrollback, as the viewport sees it: lines hidden above its top edge and + * below its bottom one. Both 0 when the pane is showing the present, and + * for a pass over anything that is not a pane's contents. */ + uint32_t above, below; + /* What "terminal default" means while shading. A cell whose colour is unset * is drawn in whatever the client's terminal calls default, and we never * learn that RGB — but most terminal text is default-coloured, so a shader diff --git a/src/slosh.h b/include/slosh.h index 834879f..834879f 100644 --- a/src/slosh.h +++ b/include/slosh.h @@ -4249,6 +4249,19 @@ static void note_animation(app_t *a, const shader_t *chain, size_t n) { } } +/* Scrollback as the viewport sees it, for content and chrome passes alike, so + * an expression can say "there is more this way": lines hidden above the top + * edge, and below the bottom. `total` from pane_scroll_pos is already the + * scrollable overhang (history minus the viewport), so the split needs no + * geometry of its own. */ +static void ctx_scroll(shade_ctx_t *base, const node_t *n) { + if (!n->pane) return; + uint32_t off = 0, total = 0; + pane_scroll_pos(n->pane, &off, &total); + base->above = off; + base->below = total > off ? total - off : 0; +} + /* A pane with nothing to apply costs nothing: no context is built and no cell * is visited, so an unshaded session emits the same bytes it did before. */ static void shade_leaf(app_t *a, screen_t *s, node_t *n) { @@ -4276,6 +4289,7 @@ static void shade_leaf(app_t *a, screen_t *s, node_t *n) { .default_fg = CFG.default_fg, .default_bg = CFG.default_bg, }; + ctx_scroll(&base, n); /* The screen's cursor belongs to whichever pane is focused, so it is only * this pane's cursor when this pane is the focused one. Handing it to any * other pane would have its spotlight chasing a cursor somewhere else. */ @@ -4328,6 +4342,7 @@ static void shade_chrome(app_t *a, screen_t *s, node_t *n, rect_t r, .default_fg = CFG.default_fg, .default_bg = CFG.default_bg, }; + ctx_scroll(&base, n); note_animation(a, chain, nc); shade_apply(s, chain, nc, r, hole, &base); } diff --git a/src/config.c b/src/config.c index 48622b2..2d65998 100644 --- a/src/config.c +++ b/src/config.c @@ -687,6 +687,120 @@ static void apply_dim_unfocused(config_t *c, bool declared) { c->state_n[PSTATE_UNFOCUSED] = 1; } +/* One derived pass: a shader whose amount is a compiled-in expression, + * written into `sh` with its program registered on the config, which owns + * every program. The sources are string literals in this file, so a compile + * failure is a can't-happen guard rather than a path with a story -- the + * caller just stops deriving and ships what it has. */ +static bool derived_pass(config_t *c, shader_t *sh, const char *kind, + color_t color, uint8_t channels, const char *src) { + shader_make(sh, kind, color, 128); + sh->channels = channels; + char eerr[128] = {0}; + expr_prog_t *p = expr_compile(src, eerr, sizeof eerr); + if (!p) return false; + sh->amount_expr = p; + c->exprs = realloc(c->exprs, (c->nexprs + 1) * sizeof *c->exprs); + c->exprs[c->nexprs++] = p; + return true; +} + +/* The scrolled default, derived *after* the theme block is read rather than + * baked from the compiled palette a theme was about to replace. `declared` is + * whether the config named `scrolled` itself, in which case its chain -- + * including an empty one -- stands. + * + * The wash: the scroll indicator's own colour (theme's scroll_bg), weak + * (about 9%) because scrollback is something you are reading through it. + * + * The edge fades: the viewport's top and bottom rows melt towards an edge + * while there is content past it -- `above`/`below` are the lines hidden past + * each edge, so `(above > 0)` snaps the top fade off at the top of the + * buffer: an edge you cannot scroll past renders solid, which is the whole + * message. (Reaching the bottom ends the state itself, same statement.) Up to + * three rows a side and never more than a quarter of the viewport each, + * because two three-row fades on a six-row viewport is every row faded and + * nothing said. They ride after the wash so they dim washed cells rather + * than racing it. */ +#define SCROLL_FADE_TOP "(above > 0) * max(0, (min(3, rows / 4) - y) * 45)" +#define SCROLL_FADE_BOTTOM \ + "(below > 0) * max(0, (y - rows + min(3, rows / 4) + 1) * 45)" + +static void apply_scrolled(config_t *c, bool declared) { + if (declared) return; + shader_t *chain = c->state_shaders[PSTATE_SCROLLED]; + c->state_n[PSTATE_SCROLLED] = 0; + shader_make(&chain[0], "tint", c->scroll_bg, 22); + c->state_n[PSTATE_SCROLLED] = 1; + if (!derived_pass(c, &chain[1], "dim", (color_t){0}, 0, SCROLL_FADE_TOP)) + return; + c->state_n[PSTATE_SCROLLED] = 2; + if (!derived_pass(c, &chain[2], "dim", (color_t){0}, 0, SCROLL_FADE_BOTTOM)) + return; + c->state_n[PSTATE_SCROLLED] = 3; +} + +/* What an unanswered bell does to the frame of the pane that rang: three + * full-strength blinks over the first 900ms -- the part that catches the eye + * the moment it rings -- then a slow breathe, so a bell nobody answered stays + * findable without nagging. The breathe's phase constant starts it at its + * dimmest (sin(since/8 + 158) is about -1 at since=900), so the hand-off from + * the last dark blink is a fade-in rather than a pop. */ +#define BELL_FLASH_AMOUNT \ + "since < 900 ? (since / 150 % 2 == 0) * 255 : 120 + sin(since / 8 + 158) / " \ + "3" + +/* ...and to its body, for those same 900ms and not a millisecond longer: a + * shimmer -- one soft diagonal sheen gliding across, the way light crosses + * something glossy. Deliberately quiet next to the frame: peak 95 where the + * blinks are 255, with a fade slow enough (since / 64) that the band keeps + * its strength across the whole sweep and the 900ms cut is what ends it. `x + 2 * y` keeps the band at a true diagonal on + * a terminal's 1:2 cells, and motion is the whole trick: the eye is pulled by + * something *moving* long before it is pulled by something bright. The band's + * width breathes on a sine while it travels -- the falloff slope swings 6±2 + * over roughly one swell per lifetime (sin is -255..255, so /96 is ±2), about + * ±14 to ±27 columns -- which is what makes it read as a living gleam rather + * than a ruled stripe. The shimmer is the announcement, the frame the + * reminder. */ +#define BELL_SHIMMER_AMOUNT \ + "(since < 900) * " \ + "max(0, 95 - abs(x + 2 * y - since / 4) * (6 + sin(since / 2) / 96) - " \ + "since / 64)" + +/* The shimmer's colour: the bell colour softened halfway towards the theme's + * default_fg -- light crossing the pane rather than paint laid on it. Derived + * from both ends of the theme, so it follows either being changed. */ +static color_t bell_sheen(const config_t *c) { + return (color_t){.set = true, + .r = (uint8_t)((c->bell.r + c->default_fg.r) / 2), + .g = (uint8_t)((c->bell.g + c->default_fg.g) / 2), + .b = (uint8_t)((c->bell.b + c->default_fg.b) / 2)}; +} + +/* Derived like the scrolled wash, and for the same reason: both passes are in + * theme's `bell` colour, so they are built after the theme is read and a + * theme moves the mark, the flash and the shimmer together. The frame pass is + * `channel="fg"`, because a frame's background is the terminal's own default + * and colouring glyphs is the whole job; the body pass keeps both channels, + * because most of a body is blank cells whose background is the only thing a + * shimmer can travel across. It follows `bell_indicator` off -- that knob's + * promise is "silent *and* invisible" -- and a `states { bell { } }` chain + * somebody wrote replaces it, like every state. The expressions read `since`, + * so the frame clock this costs runs only while a rung pane is on screen. */ +static void apply_bell(config_t *c, bool declared) { + if (declared) return; + c->state_n[PSTATE_BELL] = 0; + c->chrome_state_n[PSTATE_BELL] = 0; + if (!c->bell_indicator) return; + + if (derived_pass(c, &c->chrome_state_shaders[PSTATE_BELL][0], "tint", c->bell, + SHADE_FG, BELL_FLASH_AMOUNT)) + c->chrome_state_n[PSTATE_BELL] = 1; + if (derived_pass(c, &c->state_shaders[PSTATE_BELL][0], "tint", bell_sheen(c), + 0, BELL_SHIMMER_AMOUNT)) + c->state_n[PSTATE_BELL] = 1; +} + void config_defaults(config_t *c) { memset(c, 0, sizeof *c); c->gap = 1; @@ -777,9 +891,8 @@ void config_defaults(config_t *c) { c->default_fg = rgb(0xff, 0xff, 0xff); c->default_bg = rgb(0x00, 0x00, 0x00); - /* The one state with an opinion out of the box: while a pane is being - * dragged, everything it could be dropped onto is pushed back so the pane in - * your hand stands out. Everything else is empty until asked for. */ + /* While a pane is being dragged, everything it could be dropped onto is + * pushed back so the pane in your hand stands out. */ shader_make(&c->state_shaders[PSTATE_DROP_TARGET][0], "grayscale", (color_t){0}, 200); shader_make(&c->state_shaders[PSTATE_DROP_TARGET][1], "dim", (color_t){0}, @@ -790,21 +903,12 @@ void config_defaults(config_t *c) { shader_make(&c->state_shaders[PSTATE_DROP_HOVER][1], "dim", (color_t){0}, 140); c->state_n[PSTATE_DROP_HOVER] = 2; - /* The states with an opinion, and the line between those and the ones - * without it: - * - * a pane that is *not live* gets one — dead, suspended, scrolled. In all - * three the cells are showing something other than a running program's - * present: output from something that has exited, a pane that never - * started, or the past. You cannot discover any of that by looking unless - * something says so, and that is the whole argument for the feature; - * - * a pane that is merely *not the one you are in* does not — unfocused, - * dragging. That is ambient contrast, which is a taste, and shipping a - * taste as a default is how a tool gets a reputation for fighting you. - * - * All three are gentle on purpose. A dead pane, a suspended one and - * scrollback are all things you still want to read. */ + /* Which states ship a default, and why the line falls where it does, is + * argued in full in config/config.kdl (the states section) -- one copy of + * that essay is one that cannot drift. The short form: not-live states + * (dead, suspended, scrolled) and news (bell) get one; unfocused gets one + * through the dim_unfocused knob; dragging gets none. All gentle, because + * every one of them is a pane you still want to read. */ shader_make(&c->state_shaders[PSTATE_DEAD][0], "grayscale", (color_t){0}, 200); shader_make(&c->state_shaders[PSTATE_DEAD][1], "dim", (color_t){0}, 90); @@ -819,7 +923,13 @@ void config_defaults(config_t *c) { apply_dim_unfocused(c, false); - const color_t accent = rgb(0xff, 0x5f, 0xd7); + /* Muted blue on neutral dark: the accent has to say "this one" on the + * focused frame, the guide and the active tab without shouting over the + * text it frames, and blue is the one hue that reads as focus/selection + * everywhere else, sits apart from the red-orange reserved for `dead`, and + * survives the common colour-vision deficiencies doing it. The house pink + * lives on as contrib/themes/sl0p.kdl, one include away. */ + const color_t accent = rgb(0x7a, 0xa2, 0xf7); const color_t ink = rgb(0x14, 0x14, 0x18); const color_t dim = rgb(0x45, 0x45, 0x4a); const color_t bright = rgb(0xff, 0xff, 0xff); @@ -840,13 +950,9 @@ void config_defaults(config_t *c) { c->scroll_fg = ink; c->scroll_bg = accent; - /* Looking at the past, said in colour as well as in the ▲ count: a wash of - * the same accent the scroll indicator uses, so a theme moves both together - * rather than leaving a hardcoded hue nobody can reach. Weak (about 9%) — - * it has to survive being read through. Attached here rather than beside - * the other states because it is the one that needs the palette. */ - shader_make(&c->state_shaders[PSTATE_SCROLLED][0], "tint", c->scroll_bg, 22); - c->state_n[PSTATE_SCROLLED] = 1; + /* After scroll_bg above, and re-derived after a config's theme block: the + * rationale lives at apply_scrolled. */ + apply_scrolled(c, false); c->header = dim; c->header_hover = accent; @@ -871,9 +977,17 @@ void config_defaults(config_t *c) { c->finder_sel_fg = ink; c->finder_sel_bg = accent; - c->bell = accent; + /* The two colours that mean something rather than match something: a bell + * is attention, so amber, not the accent -- painted in the focus colour it + * said nothing -- and a dead pane is warm red-orange. Both sit apart from + * the blue accent and from each other. */ + c->bell = rgb(0xe0, 0xaf, 0x68); c->dead = rgb(0xff, 0x87, 0x5f); + /* After c->bell above, and re-derived after a config's theme block: the + * rationale lives at apply_bell. */ + apply_bell(c, false); + /* A surface, not a hole: lighter than the dimmed screen behind it, with a * border in the accent so the edge is never in doubt. The button is a grey * that is *visible* on that surface — the first version used the pane @@ -1307,7 +1421,15 @@ static void cb_chain(cfgbuf_t *b, const char *indent, const shader_t *sh, size_t n, bool chrome) { for (size_t i = 0; i < n; i++) { if (!sh[i].kind) continue; - cb_add(b, "%s%s amount=%u", indent, sh[i].kind, sh[i].amount); + /* An expression is written back as the line somebody wrote; only a + * numeric amount is a number. Pretending otherwise is how a dumped + * config used to lose every expression it contained. */ + if (sh[i].amount_expr && expr_source(sh[i].amount_expr)) { + cb_add(b, "%s%s amount=", indent, sh[i].kind); + cb_qval(b, expr_source(sh[i].amount_expr)); + } else { + cb_add(b, "%s%s amount=%u", indent, sh[i].kind, sh[i].amount); + } if (sh[i].color.set) cb_add(b, " color=\"#%02x%02x%02x\"", sh[i].color.r, sh[i].color.g, sh[i].color.b); @@ -1321,6 +1443,33 @@ static void cb_chain(cfgbuf_t *b, const char *indent, const shader_t *sh, } } +/* Whether a state's chain is still the one the loader derives rather than one + * somebody wrote: `unfocused` from the dim_unfocused knob, `scrolled` from + * theme's scroll_bg. Field-wise rather than memcmp, because a struct copy + * carries padding nobody initialised. */ +static bool state_is_derived(const config_t *c, int st) { + switch (st) { + /* bell and scrolled carry compiled expressions, which cannot be compared + * structurally -- but they also cannot be written by a config, so the + * declared flags (persisted across an include chain) are the whole test. */ + case PSTATE_BELL: return !c->bell_declared; + case PSTATE_SCROLLED: return !c->scrolled_declared; + /* unfocused has no flag -- the knob is re-applied per file -- so it is + * compared against what the knob would build: exactly one plain dim at the + * knob's strength, or nothing when the knob is 0. */ + case PSTATE_UNFOCUSED: { + if (c->chrome_state_n[st]) return false; + if (!c->dim_unfocused) return c->state_n[st] == 0; + if (c->state_n[st] != 1) return false; + const shader_t *got = &c->state_shaders[st][0]; + return got->kind && strcmp(got->kind, "dim") == 0 && !got->amount_expr && + got->amount == c->dim_unfocused && !got->color.set && !got->param && + !got->channels; + } + default: return false; + } +} + char *config_render(const config_t *c) { cfgbuf_t b = {0}; @@ -1462,6 +1611,32 @@ char *config_render(const config_t *c) { cb_add(&b, "\n// ---- what a pane looks like in a given state ----\nstates {\n"); for (int st = 0; st < PSTATE_COUNT; st++) { + /* The derived states are written as comments while they still match + * their derivation: declaring a state replaces its default outright, so a + * dump that declared these would pin what is meant to keep following the + * dim_unfocused knob and the theme -- and `C-a e` seeds a fresh config + * with exactly this text, which is the moment nobody has declared + * anything yet. The round trip is unharmed, because loading the comment + * derives the identical chain. A chain somebody replaced no longer + * matches, and is written out declared, as it must be. */ + if (state_is_derived(c, st)) { + const char *why = + st == PSTATE_BELL ? "a body shimmer, and a frame " + "blink-then-breathe, in theme's bell " + "colour" + : st == PSTATE_SCROLLED ? "a wash of theme's scroll_bg, and edge " + "fades where more content is" + : "the dim_unfocused knob above"; + cb_add(&b, " // %s { // derived: %s\n", + pane_state_name((pane_state_t)st), why); + cb_chain(&b, " // ", c->state_shaders[st], c->state_n[st], false); + cb_chain(&b, " // ", c->chrome_state_shaders[st], + c->chrome_state_n[st], true); + if (st == PSTATE_BELL && !c->state_n[st] && !c->chrome_state_n[st]) + cb_add(&b, " // // nothing: bell_indicator is false\n"); + cb_add(&b, " // }\n"); + continue; + } cb_add(&b, " %s {\n", pane_state_name((pane_state_t)st)); cb_chain(&b, " ", c->state_shaders[st], c->state_n[st], false); cb_chain(&b, " ", c->chrome_state_shaders[st], c->chrome_state_n[st], @@ -2036,6 +2211,8 @@ static bool load_into(config_t *c, const char *path, int depth, char *err, continue; } if (st == PSTATE_UNFOCUSED) unfocused_declared = true; + if (st == PSTATE_SCROLLED) c->scrolled_declared = true; + if (st == PSTATE_BELL) c->bell_declared = true; parse_shader_list(c, k, c->state_shaders[st], &c->state_n[st], c->chrome_state_shaders[st], &c->chrome_state_n[st], err, errcap); @@ -2055,6 +2232,11 @@ static bool load_into(config_t *c, const char *path, int depth, char *err, "bad colour for %s: %s", THEME_COLORS[i].name, v); } } + /* After the theme, so the wash follows whatever scroll_bg the theme just + * chose -- a config that wrote its own `scrolled` chain keeps it, whether + * the chain was written here or in a file this one included. */ + apply_scrolled(c, c->scrolled_declared); + apply_bell(c, c->bell_declared); const kdl_node_t *keys = kdl_child(root, "keys"); if (keys) { @@ -57,7 +57,9 @@ enum { V_CURSOR, V_FOCUSED, V_T, - V_SINCE + V_SINCE, + V_ABOVE, + V_BELOW }; /* Angles are counted in degrees here (see `isin`), and pi is not a number in an @@ -99,6 +101,12 @@ static const struct { /* Also a clock, so it carries the same dependency: never cached, and the * session keeps painting while something reads it. */ {"since", V_SINCE, EXPR_DEP_TIME}, + /* Scrollback, as the viewport sees it: lines hidden above its top edge, + * and below its bottom one. Both 0 at the present. A dependency of their + * own rather than a clock: they change per scroll event, not per frame, + * so the map is reused while the position holds still. */ + {"above", V_ABOVE, EXPR_DEP_SCROLL}, + {"below", V_BELOW, EXPR_DEP_SCROLL}, }; /* cols/rows are a dependency even though the map's key always carries the @@ -127,10 +135,12 @@ struct expr_prog { * one place that outlives a frame. The key is every input the compiler says * the program reads, which is what makes a stale map unrepresentable rather * than merely unlikely. */ + char *src; /* what was compiled, for the dump to render back out */ uint8_t *map; size_t map_cap; bool map_valid; int k_cols, k_rows, k_curx, k_cury, k_cursor, k_focused; + int k_above, k_below; }; /* ---- lexer -------------------------------------------------------------- */ @@ -511,6 +521,8 @@ static int vm_run(const expr_prog_t *pr, const expr_env_t *env) { [V_SINCE] = (int32_t)(env->since < 0 ? 0 : env->since > 0x7fffffff ? 0x7fffffff : env->since), + [V_ABOVE] = env->above, + [V_BELOW] = env->below, }; for (size_t i = 0; i < pr->n; i++) { @@ -735,15 +747,21 @@ expr_prog_t *expr_compile(const char *src, char *err, size_t errcap) { pr->value = vm_run(pr, &zero); pr->constant = true; } + /* The source, kept: a program lives in configs that are dumped back out, + * and bytecode cannot be un-compiled into the line somebody wrote. */ + pr->src = strdup(src); return pr; } void expr_free(expr_prog_t *p) { if (!p) return; + free(p->src); free(p->map); free(p); } +const char *expr_source(const expr_prog_t *p) { return p ? p->src : NULL; } + unsigned expr_deps(const expr_prog_t *p) { return p ? p->deps : 0; } int expr_constant(const expr_prog_t *p) { return p ? p->value : 0; } @@ -769,6 +787,8 @@ bool expr_amount_map(expr_prog_t *p, const expr_env_t *env, uint8_t **out) { same = p->k_curx == env->curx && p->k_cury == env->cury && p->k_cursor == env->cursor; if (same && (p->deps & EXPR_DEP_FOCUS)) same = p->k_focused == env->focused; + if (same && (p->deps & EXPR_DEP_SCROLL)) + same = p->k_above == env->above && p->k_below == env->below; if (!same) { if (p->map_cap < cells) { @@ -792,6 +812,8 @@ bool expr_amount_map(expr_prog_t *p, const expr_env_t *env, uint8_t **out) { p->k_cury = env->cury; p->k_cursor = env->cursor; p->k_focused = env->focused; + p->k_above = env->above; + p->k_below = env->below; } *out = p->map; return true; diff --git a/src/shader.c b/src/shader.c index b748e21..2cd5375 100644 --- a/src/shader.c +++ b/src/shader.c @@ -409,6 +409,8 @@ void shade_apply(screen_t *s, const shader_t *shaders, size_t n, rect_t r, env.focused = ctx.focused; env.t = ctx.now_ms; env.since = ctx.state_ms; + env.above = (int)ctx.above; + env.below = (int)ctx.below; if (expr_deps(sh->amount_expr) == 0) { local.amount = (uint8_t)clamp255(expr_constant(sh->amount_expr)); } else { diff --git a/tests/expr_test.c b/tests/expr_test.c index 19968d1..4745ca3 100644 --- a/tests/expr_test.c +++ b/tests/expr_test.c @@ -286,6 +286,25 @@ int main(void) { refused("a ternary without its colon", "1 ? 2"); refused("something that is not an expression at all", "@@@"); + printf("\n-- the source survives compilation\n"); + { + /* The dump has to write back the line somebody wrote: bytecode cannot be + * un-compiled, so the program keeps its text. Byte for byte, including a + * constant expression -- folding must not eat the spelling. */ + const char *src = "(y % 2) * 40"; + char err[128] = {0}; + expr_prog_t *p = expr_compile(src, err, sizeof err); + ok("a program remembers its source", + p && expr_source(p) && strcmp(expr_source(p), src) == 0, + p ? expr_source(p) : err); + if (p) expr_free(p); + p = expr_compile("1 + 2", err, sizeof err); + ok("even one that folded to a constant", + p && expr_source(p) && strcmp(expr_source(p), "1 + 2") == 0, + p ? expr_source(p) : err); + if (p) expr_free(p); + } + printf("\n-- totality: there is no loop to write\n"); { /* The language has no way to express unbounded work, so this is a diff --git a/tests/test_bell.py b/tests/test_bell.py index b152835..64b58aa 100644 --- a/tests/test_bell.py +++ b/tests/test_bell.py @@ -51,6 +51,129 @@ def titlebar(snap, p, n=10): return snap.line(p["y"])[p["x"] : p["x"] + n] +def frame_fg(snap, p): + """The left border, one row below the corner: a cell that is frame and + nothing else, clear of the title, the mark and the buttons.""" + return (snap.style_at(p["x"], p["y"] + 1) or {}).get("fg") + + +BELL = "#e0af68" # the default theme's bell colour +FRAME_IDLE = "#45454a" + + +def test_a_bell_flashes_the_frame_by_default(): + """The mark is one cell wide, which is not news you can see from the + corner of your eye -- so by default the frame says it too: full-strength + blinks in theme's bell colour, then a breathe until it is answered. The + blink windows are 150ms, so polling catches one; at full strength the + tint *is* the bell colour, which is what makes the assertion exact.""" + l = lay(TWO_PANES) + with Session(SH, cols=90, rows=16, layout=l) as s: + s.settle(30) + mine = [p for p in s.panes() if p["focused"]][0] + other = [p for p in s.panes() if not p["focused"]][0] + check( + "a frame nobody rang is quiet", + frame_fg(s.snapshot(), other) == FRAME_IDLE, + str(frame_fg(s.snapshot(), other)), + ) + ring(s, other["id"], mine["id"]) + snap = s.until(lambda sn: frame_fg(sn, other) == BELL) + check( + "the frame of the pane that rang lights up in the bell colour", + frame_fg(snap, other) == BELL, + str(frame_fg(snap, other)), + ) + + # The body shimmer: one soft diagonal sheen of the bell colour + # gliding across the pane over the first 900ms. A blank cell's + # background is black until the band reaches it, so "the shimmer + # passed here" is a background that is not. + cx = other["content_x"] + other["content_w"] // 2 + cy = other["content_y"] + other["content_h"] // 2 + + def body_bg(sn): + return (sn.style_at(cx + 6, cy) or {}).get("bg") + + snap = s.until(lambda sn: body_bg(sn) not in (None, "#000000")) + check( + "a shimmer sweeps the body of the pane that rang", + body_bg(snap) not in (None, "#000000"), + str(body_bg(snap)), + ) + # ...and it is temporary: past 900ms the body is clean again while + # the bell still stands -- asserted on the mark rather than the frame, + # because the mark is state and the frame is mid-animation. The + # announcement ends; the reminder stays. + s.settle(1100) + snap = s.snapshot() + check( + "and it is gone again while the bell still stands", + body_bg(snap) in (None, "#000000") and MARK in titlebar(snap, other), + f"body {body_bg(snap)}, titlebar {titlebar(snap, other)!r}", + ) + # Answering is looking, same as the mark: the flash must end with it, + # not on its own schedule. + s.api("focus", id=other["id"]) + s.settle(30) + snap = s.until(lambda sn: frame_fg(sn, other) not in (BELL, None)) + got = frame_fg(snap, other) + check("and looking at it puts the flash out", got != BELL, str(got)) + os.unlink(l) + + +def test_the_flash_follows_the_theme_and_the_indicator(): + """Derived, not stored: theme's `bell` moves the flash with the mark, and + `bell_indicator false` -- whose promise is silent *and* invisible -- takes + the flash with it.""" + l = lay(TWO_PANES) + c = cfg('theme {\n bell "#00ff00"\n}\n') + with Session(SH, cols=90, rows=16, layout=l, config=c) as s: + s.settle(30) + mine = [p for p in s.panes() if p["focused"]][0] + other = [p for p in s.panes() if not p["focused"]][0] + ring(s, other["id"], mine["id"]) + snap = s.until(lambda sn: frame_fg(sn, other) == "#00ff00") + check( + "the flash is in the theme's bell colour", + frame_fg(snap, other) == "#00ff00", + str(frame_fg(snap, other)), + ) + os.unlink(c) + + c = cfg("bell_indicator false\n") + with Session(SH, cols=90, rows=16, layout=l, config=c) as s: + s.settle(30) + mine = [p for p in s.panes() if p["focused"]][0] + other = [p for p in s.panes() if not p["focused"]][0] + ring(s, other["id"], mine["id"]) + # The first two blink windows: if it were going to flash, this is when. + for _ in range(4): + s.settle(100) + got = frame_fg(s.snapshot(), other) + if got != FRAME_IDLE: + break + check( + "bell_indicator false silences the frame too", got == FRAME_IDLE, str(got) + ) + os.unlink(c) + + c = cfg("states { bell { } }\n") + with Session(SH, cols=90, rows=16, layout=l, config=c) as s: + s.settle(30) + mine = [p for p in s.panes() if p["focused"]][0] + other = [p for p in s.panes() if not p["focused"]][0] + ring(s, other["id"], mine["id"]) + for _ in range(4): + s.settle(100) + got = frame_fg(s.snapshot(), other) + if got != FRAME_IDLE: + break + check("an empty bell state means nothing at all", got == FRAME_IDLE, str(got)) + os.unlink(l) + os.unlink(c) + + def test_a_bel_marks_the_pane_that_rang(): l = lay(TWO_PANES) with Session(SH, cols=90, rows=16, layout=l) as s: @@ -275,6 +398,8 @@ def test_a_minimised_pane_rings_on_the_bar(): if __name__ == "__main__": + test_a_bell_flashes_the_frame_by_default() + test_the_flash_follows_the_theme_and_the_indicator() test_a_bel_marks_the_pane_that_rang() test_looking_at_it_is_what_puts_it_out() test_a_bell_in_another_tab_shows_on_the_strip() diff --git a/tests/test_chrome_shaders.py b/tests/test_chrome_shaders.py index 7bbcfb2..feec133 100755 --- a/tests/test_chrome_shaders.py +++ b/tests/test_chrome_shaders.py @@ -23,7 +23,7 @@ from harness import Session, check, report # A pane that paints a known, non-default colour into its own content. GREEN = "#00ff00" -FRAME = "#ff5fd7" # the default focused frame colour +FRAME = "#7aa2f7" # the default focused frame colour DIM_FRAME = "#45454a" # ...and the colour of a frame you are not in SH = [ "/bin/sh", diff --git a/tests/test_config.py b/tests/test_config.py index 1e4cff0..cb80829 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -562,7 +562,7 @@ def test_every_surface_has_its_own_theme_name(): p = s.pane() check( "the focused frame keeps its own colour", - (snap.style_at(p["x"], p["y"] + 1) or {}).get("fg") == "#ff5fd7", + (snap.style_at(p["x"], p["y"] + 1) or {}).get("fg") == "#7aa2f7", str(snap.style_at(p["x"], p["y"] + 1)), ) @@ -587,7 +587,7 @@ def test_an_unknown_theme_name_is_refused_not_ignored(): p = s.pane() check( "and the compiled-in default is kept", - (s.snapshot().style_at(p["x"], p["y"] + 1) or {}).get("fg") == "#ff5fd7", + (s.snapshot().style_at(p["x"], p["y"] + 1) or {}).get("fg") == "#7aa2f7", str(s.snapshot().style_at(p["x"], p["y"] + 1)), ) os.unlink(conf) diff --git a/tests/test_drag.py b/tests/test_drag.py index e301fac..3265caf 100644 --- a/tests/test_drag.py +++ b/tests/test_drag.py @@ -282,7 +282,7 @@ def test_drop_target_is_visible(): run = snap.style_at(right["x"], right["y"]) check( "the drop target is highlighted while dragging", - run and run["fg"] == "#ff5fd7" and "bold" in run["attrs"], + run and run["fg"] == "#7aa2f7" and "bold" in run["attrs"], str(run), ) s.send(rf"\e[<0;{right['x'] + 5};{right['y'] + 3}m") diff --git a/tests/test_responsive.py b/tests/test_responsive.py index d3dc90d..fe88d4d 100644 --- a/tests/test_responsive.py +++ b/tests/test_responsive.py @@ -361,7 +361,7 @@ def test_a_tab_is_laid_out_or_it_is_a_list_never_both(): # ---- hovering a row in the stack ------------------------------------------- -FRAME_FOCUS = "#ff5fd7" # the rule, while hovered +FRAME_FOCUS = "#7aa2f7" # the rule, while hovered TITLE_FOCUS = "#ffffff" # the title, while hovered FRAME_IDLE = "#45454a" diff --git a/tests/test_shaders.py b/tests/test_shaders.py index 7afd643..56001a6 100644 --- a/tests/test_shaders.py +++ b/tests/test_shaders.py @@ -407,7 +407,7 @@ def test_the_hovered_target_is_still_highlighted_over_the_dashes(): run = snap.style_at(right["x"], right["y"]) check( "the pane under the pointer keeps its drop highlight", - run and run["fg"] == "#ff5fd7" and "bold" in run["attrs"], + run and run["fg"] == "#7aa2f7" and "bold" in run["attrs"], str(run), ) release(s, right["x"] + 5, right["y"] + 3) @@ -503,7 +503,7 @@ def test_positional_shaders_stay_off_the_chrome(): snap = s.snapshot() check( "a full-strength positional stack still leaves the frame alone", - frame_fg(snap, p) == "#ff5fd7", + frame_fg(snap, p) == "#7aa2f7", str(frame_fg(snap, p)), ) diff --git a/tests/test_states.py b/tests/test_states.py index ce32ac3..a0f47f2 100644 --- a/tests/test_states.py +++ b/tests/test_states.py @@ -116,6 +116,56 @@ def test_scrollback_is_coloured_by_default(): ) +def test_scrollback_fades_at_the_edges_that_continue(): + """While scrolled, the viewport's top and bottom rows melt towards the + edge -- the way a scrollable list fades where it continues -- and each + fade exists only while there is content past that edge: `(above > 0)` is + a binary gate, so hitting the top of the buffer turns the top edge solid. + Reaching the bottom ends the scrolled state entirely, which is the same + statement about the other edge.""" + with Session(SH, cols=60, rows=20, config=cfg()) as s: + s.until_text("line 39") + pane = s.pane() + mid = pane["content_h"] // 2 + last = pane["content_h"] - 1 + + s.send(r"\x01\x1b[5~") # C-a PgUp: mid-buffer, content both ways + s.settle(30) + snap = s.snapshot() + top, m, bot = (fg(snap, pane, row=r) for r in (0, mid, last)) + check( + "mid-buffer, the top rows melt into the edge", + top != m, + f"top {top}, mid {m}", + ) + check("...and the bottom rows too", bot != m, f"bottom {bot}, mid {m}") + + s.send(r"\x01\x1b[H") # C-a Home: the very top of the buffer + s.settle(30) + snap = s.snapshot() + top, m, bot = (fg(snap, pane, row=r) for r in (0, mid, last)) + check( + "at the top of the buffer the top edge turns solid", + top == m, + f"top {top}, mid {m}", + ) + check( + "while the bottom still says the present is below", + bot != m, + f"bottom {bot}, mid {m}", + ) + + s.send(r"\x01\x1b[F") # C-a End: back to the present + s.settle(30) + snap = s.snapshot() + top, m, bot = (fg(snap, pane, row=r) for r in (0, mid, last)) + check( + "and the present is opaque everywhere", + top == m == bot, + f"top {top}, mid {m}, bottom {bot}", + ) + + def test_an_unfocused_pane_is_dimmed_by_default(): """This used to assert the opposite, deliberately: ambient contrast is a taste, and the argument against shipping a taste was that turning it off @@ -184,6 +234,69 @@ def test_a_states_block_beats_the_knob(): os.unlink(conf.name) +def test_the_scrolled_wash_follows_the_theme(): + """The wash over scrollback is theme's scroll_bg, and that promise is only + kept if the wash is derived *after* the theme block is read: it used to be + baked from the compiled palette, so every theme shipped left the default + accent smeared over its scrollback. A chain somebody wrote still stands, + whichever file of an include chain it was written in.""" + + def scrolled_fg(text, include=None): + d = tempfile.mkdtemp(prefix="slosh-scrolled-") + if include is not None: + open(os.path.join(d, "inc.kdl"), "w").write(include) + conf = os.path.join(d, "config.kdl") + # One theme block per file: the loader reads the first node by name, + # so a second `theme { }` would be a block that quietly says nothing. + open(conf, "w").write(text) + with Session(SH, cols=60, rows=12, config=conf) as s: + s.until_text("line 39") + pane = s.pane() + s.send(r"\x01\x1b[5~") # C-a PgUp: into the scrollback + s.settle(20) + # Mid-viewport, clear of the derived edge fades (three rows a + # side): this test is about the wash, and the wash alone. + got = fg(s.snapshot(), pane, row=pane["content_h"] // 2) + return got + + # White text tinted 22/255 towards pure green keeps green at full and + # pulls the other channels down: green stays the largest channel, which is + # the assertion, so the exact rounding stays the implementation's. + def greenish(c): + return c is not None and c[3:5] == "ff" and c[1:3] < "ff" + + base = ( + "theme {\n" + ' default_fg "#ffffff"\n' + ' default_bg "#000000"\n' + ' scroll_bg "#00ff00"\n' + "}\n" + ) + + got = scrolled_fg(base) + check( + "a theme's scroll_bg moves the wash with the indicator", greenish(got), str(got) + ) + + got = scrolled_fg( + base + 'states { scrolled { tint amount=255 color="#ff0000" } }\n' + ) + check("a chain you wrote beats the derivation", got == "#ff0000", str(got)) + + got = scrolled_fg('include "inc.kdl"\n', include=base) + check("it follows a theme brought in by an include", greenish(got), str(got)) + + got = scrolled_fg( + 'include "inc.kdl"\n' + base, + include='states { scrolled { tint amount=255 color="#ff0000" } }\n', + ) + check( + "and a chain written in an include is not re-derived over", + got == "#ff0000", + str(got), + ) + + def test_a_flattened_tab_still_says_which_panes_are_not_live(): """A collapsed header is chrome, and the shader pass never touches chrome (D13) — so the words have to carry what the colour carries everywhere diff --git a/tests/test_tabs.py b/tests/test_tabs.py index 3ae570a..0583ad3 100644 --- a/tests/test_tabs.py +++ b/tests/test_tabs.py @@ -309,7 +309,7 @@ def test_json_api(): # ---- hovering the strip ---------------------------------------------------- -ACCENT = "#ff5fd7" # the fill of the tab you are in, and hover on the rest +ACCENT = "#7aa2f7" # the fill of the tab you are in, and hover on the rest INK = "#141418" # text on that fill BRIGHT = "#ffffff" # that text while the pointer is on it DIM = "#45454a" # a tab you are not in diff --git a/tests/test_wide_marks.py b/tests/test_wide_marks.py index 9438a64..11ea5f6 100644 --- a/tests/test_wide_marks.py +++ b/tests/test_wide_marks.py @@ -39,7 +39,10 @@ def run(mark, cols=100, rows=14): cfg = tempfile.NamedTemporaryFile("w", suffix=".kdl", delete=False) # An unmistakable bell colour: the assertion is "how many columns did the # mark claim", which means finding those columns without guessing. - cfg.write('bell_mark "%s"\ntheme { bell "#00ff00" }\n' % mark) + # ...and without the default bell flash: it paints the whole frame in + # that same colour at full strength, which would make "the first column + # that is not the bell colour" the far corner of the pane. + cfg.write('bell_mark "%s"\ntheme { bell "#00ff00" }\nstates { bell { } }\n' % mark) cfg.close() p = subprocess.run( [ |
