Skip to content

Rewrite --palette / --bands / wasm Session for the fx engine - #52

Closed
csfh wants to merge 1 commit into
omacom:masterfrom
csfh:cursor/fx-palette-bands-066c
Closed

csfh wants to merge 1 commit into
omacom:masterfrom
csfh:cursor/fx-palette-bands-066c

Conversation

@csfh

@csfh csfh commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Rewrites omacom/ttfx#29 for ttfx 0.5 so --palette and --bands work on src/fx instead of only the original engine.

Why

#29's palette/bands only changed the old engine. After #44/#47 every CLI run goes through fx, so those flags would be ignored and draw the wrong colours. This branch starts from current omacom/master and implements the flags on both engines.

What landed

  • --palette HEX[,HEX...] replaces each effect's default colours. Effect-specific colour flags given on the command line keep their values.
  • --bands requires --palette and colours the input word in five field stripes (crest/hover/lit/mid/dim at 4-3-4-3-5). 19-line input stays that ratio; other heights use a Hamilton split. Existing-colour handling is always so every effect settles on those stripes.
  • Shared clap configs are recoloured once; fx and the original engine both see the same config. Bands write input colours on the original arena and on fx's ch.fg / CF_PREEXISTING.
  • Wasm Session wraps fx (palette, optional terminal background, bands) so WTE / omacom.org / the screensaver can share the fast engine.
  • Oracle cases in tools/fx/cases/decrypt.txt and wipe.txt.

This supersedes #29. The old PR cannot rebase cleanly onto fx and should close in favour of this one.

Fork mirror (same branch): https://github.com/csfh/ttfx/pull/2

Test plan

  • cargo test --lib — 57 passed, including bands/palette
  • cargo test --tests — integration goldens passed
  • ttfx --help shows --palette and --bands
  • --bands without --palette exits 1
  • echo OMARCHY | ttfx --palette '#daecc6,#bbdd97,#9ece6a,#678549,#39482e' --bands decrypt — all five palette RGBs appear; fx vs original parity-dump matches
  • tools/fx/oracle.sh decrypt quick — 420 passed, 0 failed
  • tools/fx/oracle.sh wipe quick — 628 passed, 0 failed

Rewrites #29 for ttfx 0.5: palette and field bands apply to
shared effect configs and to both engines, the wasm Session wraps fx,
and oracle cases cover the new flags.

Co-authored-by: Christoffer Hallas <github@christofferhallas.com>
@csfh
csfh marked this pull request as ready for review September 29, 2026 13:33
@csfh

csfh commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

Ready to merge from our side.

csfh is pull-only on this repo, so we need a maintainer to merge.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 8b27dcf. The CLI half (--palette, --bands) works and holds parity between the two engines. The wasm Session does not run in its current form: every constructor call traps.

What ran, on a disposable Arch worker (never on the machine holding credentials):

  • ./bin/test in full: green. 57 lib tests, cli corpus 19/19, effect parity 354/354, tty parity 41/41, sigterm, terminal-close and resize behaviour all passed.
  • fx against the original engine (TTFX_FX=force vs TTFX_FX=0) for all 37 effects, not just decrypt and wipe, under --palette with three colours, --palette with five colours plus --bands, and a single-colour --palette plus --bands. Three inputs (plain, multi-row, ANSI-coloured) and two seeds each: 666 of 666 byte-identical. tools/fx/oracle.sh is not part of bin/test or CI, so this is the only place the new cases have been run against every effect.
  • The last frame of every effect under --bands: 33 of 37 end on exactly the five palette colours. The other four (beams, overflow, smoke, sweep) show extra colours only on a ragged 10-line input, and they show the same extras with --existing-color-handling always on ANSI-coloured input without either new flag. That behaviour is already in the engine, not introduced here.
  • The wasm library, built with cargo rustc --lib --release --target wasm32-unknown-unknown --crate-type cdylib, passed through wasm-bindgen 0.2.129 and driven from node.

Wasm Session: three defects, all reproduced on the worker

  1. new Session(...) traps with unreachable for every effect and seed. Engine::new calls Terminal::parse, which sets last_time_printed: Instant::now() (src/engine/terminal.rs:388), and Instant::now() panics on wasm32-unknown-unknown. When I replaced that one initialiser in a scratch copy, decrypt, wipe and print ran to completion on the palette colours. That confirms this line is the cause. A fix needs a clock that works on this target, such as an Option<Instant> set on the first paced frame, which wasm never reaches.
  2. With no seed (undefined, NaN or infinity), Rng::from_entropy() (src/wasm.rs:46) reads /dev/urandom, which doesn't exist in a browser. It still trapped once the first defect was patched. js_sys::Math::random() is already available through the new dependency, or the seed could be made required.
  3. Session::step calls next_frame but never advances the engine's virtual clock, which run_effect and dump_effect do through Engine::frame. Matrix and thunderstorm therefore never finish: with the first defect patched, matrix was still running after 200,000 steps. The CLI finishes the same input in 1,177 frames, and thunderstorm in 911. step needs the same clock.advance_frame() the CLI loop does.

CI never builds the wasm target, which is how all three got through. A CI job that builds the cdylib and steps one Session in node would catch them. I couldn't push fixes, because the branch doesn't allow maintainer edits.

Worth deciding (judgement calls, not defects)

  • Size. At +1680 lines this is three separable changes: --palette with its oracle cases, --bands, and the wasm Session with pack_display_frame, the cfg gates and the new dependencies. The CLI flags are ready as they stand. The wasm part isn't, and splitting it out would let the flags land without waiting on it. There is also some unrelated rustfmt reformatting of untouched lines in src/cli.rs and the build_effect match in src/effects/mod.rs.
  • --bands is tuned to the Omarchy wordmark. The 19-unit field and the body-row heuristic (src/utils/bands.rs:117) are designed around that logo. Single-line input always comes out in the dim band (checked: printf OMARCHY | ttfx --palette ... --bands wipe draws only colour 5). ANSI colours in the input are replaced.
  • Palette mapping. Every list field starts again at palette colour 0, and keeps the default's length. Decrypt's final gradient, for example, is only ever the first palette colour, so a long palette only partly shows on some effects. --palette 123 is read as xterm colour 123 even though the help says HEX, and fff is rejected.
  • Tests. every_effect_applies_a_hex_palette only checks that the config's Debug string changed. Dropping a colour field from an effect with several of them would still pass. The run of all 37 effects above covers what it can't.

Checked and fine: the --palette skip set matches clap's argument ids for every effect, and no colour field is missed. --palette after the effect name and with --random-effect both work. Bands are reapplied after a SIGWINCH rebuild in both engines. pack_display_frame picks the same winning cell and uses the same padding as fx's renderer.

Second opinion: Codex at medium effort and muse-spark-1.3 (via pi, thinking high) read the diff. Codex independently traced all three wasm defects (they were also in my own review, so take that partly as agreement, and independence is not guaranteed). It also added that cargo build --target wasm32-unknown-unknown without --lib can't compile the binary, because src/main.rs still calls the signal functions that are gated out. muse also flagged the size and the Debug-string test. Two of its findings didn't hold up: a misindexed pack_display_frame when the canvas is offset (it mirrors the renderer's padding exactly), and a divergence between the engines on all-whitespace input (both engines refuse that input with exit 1).

Next: the wasm defects are for the author. Whether to split the PR, and whether --bands belongs in ttfx in this form, is for the maintainer.

@omarchybot omarchybot added the enhancement New feature or request label Oct 24, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Following up on the review above with a way forward: please split this into two PRs.

  1. --palette and --bands on their own. This half is ready: on the worker the fx engine matched the original engine byte for byte across all 37 effects (666 of 666 runs), and the suite was green. It would help to leave out the unrelated rustfmt changes in src/cli.rs and src/effects/mod.rs, and, if you can, to make every_effect_applies_a_hex_palette check the colours it expects rather than only that the Debug string changed. Since CPU Optimization: only redraw changed terminal cells #61 and Avoid redundant hashing in circle coordinate generation #54 have now landed on master, please rebase onto it as well.
  2. The wasm Session once it runs. The three defects from the review need fixing first: Terminal::parse calls Instant::now() (src/engine/terminal.rs:388), which panics on wasm32-unknown-unknown; Rng::from_entropy() (src/wasm.rs:46) reads /dev/urandom when no seed is given; and Session::step never advances the virtual clock, so timed effects like matrix and thunderstorm never finish. A CI job that builds the wasm target and drives one effect through node would catch all three.

Maintainer edits are turned off on this branch, so we can't push either part ourselves. Reviewed by Claude Opus 5.5, with a second opinion from Codex Medium and muse-spark-1.3 (high).

@csfh csfh closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants