cape.promptutils: Useful tools for interactive CLI prompts

This includes a CAPE-specific autocompletion class CfdxCompleter, which is used in cape.ui.

cape.ui.promptutils.complete_filenames(text: str) → list[str]

Return a tab-completion suggestion based on file names

Call:
>>> suggestions = complete_filenames(text)
Inputs:
text: str

User input so far

Outputs:
suggestions: :list[class:str]

Extant files whose names start with text

cape.ui.promptutils.complete_pathcmds(text: str) → list[str]

Return a tab-completion suggestion from $PATH executables

Call:
>>> suggestions = complete_pathcmds(text)
Inputs:
text: str

User input so far

Outputs:
suggestions: :list[class:str]

Reachable executalbes whose names start with text

cape.ui.promptutils.complete_xcape(text: str) → list[str]

Return tab-completion suggestions of CAPE executables

Call:
>>> suggestions = complete_xcape(text)
Inputs:
text: str

User input so far

Outputs:
suggestions: :list[class:str]

Sortec CAPE file names that start with text

cape.ui.promptutils.complete_xfilenames(text: str) → list[str]

Return a filtered list of executable file names

Call:
>>> suggestions = complete_xfilenames(text, state)
Inputs:
text: str

User input so far; must start with "./"

Outputs:
suggestions: :list[class:str]

Extant files whose names start with text

cape.ui.promptutils.input_color(prompt: str, color: str = 'black') → str

Modify built-in input() to also set color

Call:
>>> raw = input_color(prompt, color)
Inputs:
prompt: str

Text to display prior to requesting input

color: str

Common name of color to use for prompt

Outputs:
raw: str

User’s input

cape.ui.promptutils.print_color(msg: str, color: str | list | None = None)

Print message using a specified ANSI color

Call:
>>> print_color(msg, color=None)
Inputs:
prompt: str

Text to display prior to requesting input

color: {None} | str | list

Name(s) of color (or style) to use for prompt

cape.ui.promptutils.sprintf_color(msg: str, color: str | list | None = None) → str

Create string with optional color instructions

Call:
>>> prompt = sprintf_color(msg, color=None)
Inputs:
prompt: str

Text to display prior to requesting input

color: {None} | str | list

Name(s) of color (or style) to use for prompt

Outputs:
prompt: str

String with color instructions at beginning and end

cape.ui.promptutils.sprintf_color_rl(msg: str, color: str | list | None = None) → str

Create string with color for readline input prompts

This wraps ANSI escape codes with readline’s special markers (x01 and x02) so readline can correctly calculate prompt width and handle line wrapping/cursor positioning.

Call:
>>> prompt = sprintf_color_rl(msg, color=None)
Inputs:
msg: str

Text to display prior to requesting input

color: {None} | str | list

Name(s) of color (or style) to use for prompt

Outputs:
prompt: str

String with readline-wrapped color instructions