Add terminal pipes #3

Merged
bnied merged 0 commits from refs/pull/3/head into main 2026-06-02 21:31:46 +00:00
bnied commented 2026-06-02 19:47:08 +00:00 (Migrated from codeberg.org)

Adds a working | pipe mechanic to the terminal, plus two new composable commands — figlet (block-ASCII banner text) and lolcat (rainbow colorizer) — and makes the existing echo, fortune, cat, and cowsay commands pipe-aware so they finally compose.

fortune | cowsay
figlet bnied | lolcat
echo hello | figlet | lolcat
cat about | cowsay

What changed

  • Pipe engine (js/pipeline.js) — splits input on |, runs the first stage as a source and each later stage as a filter, threading plain text between them. Returns { lines, colorize } or { error }.
  • figlet (js/figlet.js + data/figlet-font.json) — pure, data-driven renderer over a hand-authored 42-glyph 5×5 block font (A–Z, 0–9, space, ! ? . , -), uppercase-folded with a fallback glyph for unknown characters.
  • lolcat — per-character HSL rainbow rendering. In a pipe it passes text through unchanged and flips a colorize flag, so it composes anywhere.
  • Composable classicsecho / fortune / cat / cowsay now work as pipe stages.
  • Architecture — pure, DOM-free cores (js/figlet.js, js/cowsay.js, js/pipeline.js) shared by both the direct command branches in
    js/commands.js and the pipe engine. The pipe engine activates only when input contains |, so the ~40 existing commands and easter eggs are untouched.
  • Wiring — font loaded into state.DATA.figletFont; figlet/lolcat added to state.COMMANDS (tab-completion); help and README updated.
  • Tests — 17 Node --test unit tests for the pure cores, zero dependencies, no build step (one-line package.json adding "type": "module").

Test plan

  • node --test → 17 passing
  • Serve locally (python3 -m http.server 8000) and verify:
    • figlet hi renders block-ASCII text; bare figlet shows a usage line
    • lolcat hello renders rainbow text; bare lolcat shows a usage line
    • fortune | cowsay, figlet bnied | lolcat, echo hello | figlet | lolcat, cat about | cowsay
    • echo x | bogusbogus: command not found; echo x | → pipe syntax error
    • Tab-completion completes figlfiglet, lolclolcat
    • Rainbow output stays readable across themes (theme amber, theme blue)
    • No regressions: cowsay moo, ls -la, neofetch render as before

Notes

  • Security: the pipe engine returns raw text; every render path in js/commands.js escapes before it reaches innerHTML (verified — no XSS).
  • Minor known cosmetic: piping a section that contains HTML (e.g. cat contact | cowsay) shows the markup as escaped literal text. Correctly
    escaped and arguably shell-accurate; cat about | cowsay (plain text) is unaffected.
Adds a working `|` pipe mechanic to the terminal, plus two new composable commands — `figlet` (block-ASCII banner text) and `lolcat` (rainbow colorizer) — and makes the existing `echo`, `fortune`, `cat`, and `cowsay` commands pipe-aware so they finally compose. fortune | cowsay figlet bnied | lolcat echo hello | figlet | lolcat cat about | cowsay ## What changed - **Pipe engine** (`js/pipeline.js`) — splits input on `|`, runs the first stage as a source and each later stage as a filter, threading plain text between them. Returns `{ lines, colorize }` or `{ error }`. - **figlet** (`js/figlet.js` + `data/figlet-font.json`) — pure, data-driven renderer over a hand-authored 42-glyph 5×5 block font (`A–Z`, `0–9`, space, `! ? . , -`), uppercase-folded with a fallback glyph for unknown characters. - **lolcat** — per-character HSL rainbow rendering. In a pipe it passes text through unchanged and flips a `colorize` flag, so it composes anywhere. - **Composable classics** — `echo` / `fortune` / `cat` / `cowsay` now work as pipe stages. - **Architecture** — pure, DOM-free cores (`js/figlet.js`, `js/cowsay.js`, `js/pipeline.js`) shared by both the direct command branches in `js/commands.js` and the pipe engine. The pipe engine activates **only** when input contains `|`, so the ~40 existing commands and easter eggs are untouched. - **Wiring** — font loaded into `state.DATA.figletFont`; `figlet`/`lolcat` added to `state.COMMANDS` (tab-completion); `help` and `README` updated. - **Tests** — 17 Node `--test` unit tests for the pure cores, **zero dependencies, no build step** (one-line `package.json` adding `"type": "module"`). ## Test plan - [x] `node --test` → 17 passing - [x] Serve locally (`python3 -m http.server 8000`) and verify: - [x] `figlet hi` renders block-ASCII text; bare `figlet` shows a usage line - [x] `lolcat hello` renders rainbow text; bare `lolcat` shows a usage line - [x] `fortune | cowsay`, `figlet bnied | lolcat`, `echo hello | figlet | lolcat`, `cat about | cowsay` - [x] `echo x | bogus` → `bogus: command not found`; `echo x |` → pipe syntax error - [x] Tab-completion completes `figl`→`figlet`, `lolc`→`lolcat` - [x] Rainbow output stays readable across themes (`theme amber`, `theme blue`) - [ ] No regressions: `cowsay moo`, `ls -la`, `neofetch` render as before ## Notes - Security: the pipe engine returns raw text; every render path in `js/commands.js` escapes before it reaches `innerHTML` (verified — no XSS). - Minor known cosmetic: piping a section that contains HTML (e.g. `cat contact | cowsay`) shows the markup as escaped literal text. Correctly escaped and arguably shell-accurate; `cat about | cowsay` (plain text) is unaffected.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
spaceduck/site!3
No description provided.