Expand description
Interactive prompts: “press Enter to continue” and yes/no confirmation.
Prompts go to stdout, never stderr: the shell wrapper buffers stderr until the command exits, so a prompt there would not be visible while the program waits for the answer.
§The Enter prompt
wait_for_enter reads a key with the terminal in non-canonical mode and with ISIG off.
Ctrl-C is therefore an ordinary key (byte 0x03) instead of a SIGINT: the process is never
killed in the middle of the prompt, wait_for_enter returns PromptOutcome::Interrupted
and the caller carries on and exits normally. That is what lets the shell wrapper still apply
the directives (cd, export) the process emitted before it asked for Enter. The terminal
settings are restored by a drop guard, also when the read fails.
§Confirmation
confirm is the replacement of click.confirmation_option for shellgame remove.
Click prints <prompt> [y/N]: and accepts y/yes (any case) as yes, n/no or an empty
line as no, and for anything else prints “Error: invalid input” and asks again; end of input
aborts. This version accepts y, yes and, since the game is Czech, a and ano as yes.
Everything else, including empty input, end of input and unrecognised words, means no: it never
loops, so it cannot hang on a pipe, and declining is the safe answer for a destructive
action. Input is read as a line even when stdin is not a terminal, so yes | shellgame remove
works.
Enums§
- Prompt
Outcome - How
wait_for_enterended.
Constants§
- ENTER_
PROMPT_ TEXT - What the Enter prompt of a page is called in Czech: shown dimmed after a space.
Functions§
- confirm
- Asks a yes/no question on stdout and reads the answer from stdin.
- enter_
prompt - The standard Enter prompt: a space and
ENTER_PROMPT_TEXT, dimmed when colour is on. - wait_
for_ enter - Prints
promptto stdout and waits for Enter.