saturnin._scripts.repl

REPL for Typer application

Globals

saturnin._scripts.repl.kb

Prompt-toolkit key bindings

Classes

class saturnin._scripts.repl.CustomClickCompleter(cli)[source]

Bases: Completer

Custom prompt-toolkit completer.

It provides command completion for Typer/Click commands and parameters, including option/parameter values.

Parameters:

cli – Root Typer command group

get_completions(document, complete_event=None)[source]

Yields completion choices.

class saturnin._scripts.repl.IOManager(context, *, echo: Callable[[str], None] | None = None, console: Console = None)[source]

Bases: object

REPL I/O manager.

Handles command prompt, stdin/stdout redirection etc.

Parameters:
  • context – Current Click context

  • echo (Optional[EchoCallback]) – Callback called with command line before it’s executed.

  • console (Console) – Costom Rich console for output. If not provided, Saturnin standard console is used.

_get_command() str[source]

Returns next command fetched from queue, stdin or console prompt.

Return type:

str

get_command() str[source]

Returns next command.

Return type:

str

redirect_console(filename: Path) None[source]

Redirects console output to file.

Parameters:

filename (Path) – File for console output.

Return type:

None

reset_queue() None[source]

Clear command queue

Return type:

None

restore_console() None[source]

Closes the output file and restores output to console.

Return type:

None

Functions

saturnin._scripts.repl.repl(context, ioman: IOManager) bool[source]

Start an interactive shell. All subcommands are available in it.

Parameters:
  • context – Current Click context.

  • ioman (IOManager) – IOManager instance.

Returns:

True if REPL should be restarted, otherwise returns False.

Return type:

bool

If stdin is not a TTY, no prompt will be printed, but commands are read from stdin.