Skip to main content

Module env

Module env 

Source
Expand description

The process environment, read once.

Everything the game needs to know about the process it runs in is gathered here, in main, and passed down: the home directory, the user name, the working directory, where the state lives, whether the binary runs inside the game shell, and a few knobs that tests and developers use. No game logic reads std::env or the process working directory after this, so every rule below this layer is a plain function of its inputs and tests never chdir or set_var.

variablefieldmeaning
HOMEEnv::homethe logical home directory
USEREnv::userthe player’s name (player when unset)
SHELLGAME_STATE_DIR, XDG_CONFIG_HOMEEnv::state_dirwhere state.json lives
SHELLGAME_WORKSPACEEnv::workspace_overrideworkspace of a new game
SHELLGAME_WRAPPEREnv::wrappedthe binary runs inside the game shell
TMPDIREnv::tmpdira second place remove may delete from
SHELLEnv::shellthe player’s login shell, for shell detection
SHELLGAME_FORCE_SHELLEnv::force_shellbash or fish: which game shell to start
SHELLGAME_UPDATE_URLEnv::update_urlwhere shellgame update downloads from

An empty value counts as unset for every variable, as it does in the Python version, where "" is falsy. NO_COLOR and friends are not read here: anstream handles them when output is written.

Structs§

Env
What the game knows about the process it runs in. Built once by Env::from_process and passed down by reference; tests build one with Env::new or a struct literal.