Skip to main content

Module cd

Module cd 

Source
Expand description

Declarative cd policies for strict navigation levels.

Several levels teach one exact movement command (cd .., cd ../../.., cd -, an absolute path) and must reject anything else. Hand-written hooks all repeated the same steps, and each had to remember the anti-soft-lock contract. A CdPolicy states only what the level requires; the engine performs the contract, so the guarantee is structural instead of a convention every author has to re-implement.

A policy has two kinds of clause:

§The contract

The shell asks twice per cd: once before the move, once after it succeeded.

  1. Before the move (CdPolicy::pre_move): a move out of scope is allowed. A move that is lifted is allowed: the level’s cd marker exists (the player has already shown the command), or the move’s destination is the level’s start directory (the recovery move: without it one extra step could leave a player in a directory from which every permitted move leads further away). Otherwise the first failing rule blocks. The engine only returns the decision; printing the red panel and CD_RECOVERY_TIP is the UI’s job.
  2. After a successful move (CdPolicy::post_move): the level’s cd marker is recorded when the move was in scope, every rule passes (judged with the real destination) and, if the policy has an arrive directory, the player landed there. Evidence comes from scope, rules and arrive only: lifting waives blocking but never grants or denies evidence, so cd - back to level 2.2’s start directory (a lifted move) still counts. A move that failed in the shell records nothing, because the shell never reports it.
  3. on_move runs after every successful move, lifted or not, in scope or not. A level that needs its own bookkeeping (the 1.9 walk home) uses it together with manual_evidence.

Directories are compared with soft_canonicalize on both sides, so a workspace below a symlink (macOS /tmp) and a destination that does not exist yet both compare correctly.

Structs§

CdMove
One attempted (or completed) cd, with everything a clause may need to judge it.
CdPolicy
A cd policy; see the module documentation for the contract.

Enums§

CdDecision
What to do about a cd that is about to happen.

Functions§

policy
Start an empty policy: policy().exact("..", "Použijte přesně příkaz 'cd ..'.").