Skip to main content

Module prompt

Module prompt 

Source
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§

PromptOutcome
How wait_for_enter ended.

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 prompt to stdout and waits for Enter.