click_extra.cli_capture module¶

The screenshot and snippet commands of the click-extra CLI.

Both draw a document from terminal text: the first captures what a command prints, the second colors a source file, and they share the window options, the output resolution and the delivery through capture_options(), resolve_capture_format() and deliver_capture(). click_extra.cli registers them on the root group.

click_extra.cli_capture.deliver_capture(document, output)[source]¶

Write a rendered capture where --output points.

A bare - prints it instead, see is_stdout(), through click.echo() rather than a bare write: that is what strips the escape sequences when the terminal turns out to be a pipe, and what lets --color, --no-color, --accessible and NO_COLOR reach a capture, since invocation_color() carries the tri-state all four of them resolve to.

Parameters:
  • document (str) – the rendered capture.

  • output (Path) – where it goes.

Return type:

None

click_extra.cli_capture.resolve_capture_format(output, fragment)[source]¶

Read the capture format off --output, and settle --fragment on it.

Both capture commands carry the pair of options, so both carry the same rejection: --fragment asks for the bare block of a standalone document, and only HTML has one.

Parameters:
  • output (Path) – where the capture goes; its extension names the format.

  • fragment (bool) – whether the caller asked for the bare block.

Return type:

CaptureFormat

Returns:

the format to render.

Raises:

ClickException – on an extension no format claims, or on --fragment against anything but HTML.

click_extra.cli_capture.capture_options(*, columns_help, default_columns=80)[source]¶

Attach every option the two capture commands share.

screenshot pictures what a command printed and snippet pictures what a file says, but both hand their text to the same renderer, so everything from the window’s frame to its credit line is one vocabulary. Declaring it once is what stops the two drifting into near-synonyms, which is the failure a reader hits rather than a maintainer: they learn --backdrop on one command and expect it on the other.

Only the width differs, both in what it defaults to and in what it governs: a command wraps its own output to it, where a file was never wrapped at all.

Note

The options are applied in reverse, so the tuple below reads in the order --help prints. A command’s own options are declared under this decorator and land after the shared ones, which is what keeps the common vocabulary together at the top of every capture command’s help screen.

Parameters:
  • columns_help (str) – what the width means for this command.

  • default_columns (int | Literal['auto']) – the width it takes when nothing states one.

Return type:

Callable[[Callable[..., Any]], Callable[..., Any]]

Returns:

the decorator attaching all of them.

click_extra.cli_capture.SCREENSHOT_EPILOG = '\x08\nExamples:\n\n\x08\n  Draw a help screen as a picture a README can show:\n    $ click-extra screenshot --output my-cli.svg -- my-cli --help\n\n\x08\n  Draw it as selectable text, for a page you own:\n    $ click-extra screenshot --output my-cli.html -- my-cli --help\n\n\x08\n  Capture a CLI that is not built on Click Extra, colored all the same:\n    $ click-extra screenshot --output flask.svg --wrap -- flask run --help\n\n\x08\n  Record the frames a spinner draws, as an animation:\n    $ click-extra screenshot --output ripen.svg --record --columns 80 -- ripen\n'¶

Sample invocations closing the screenshot help screen.

click_extra.cli_capture.SNIPPET_EPILOG = '\x08\nExamples:\n\n\x08\n  Draw a source file as a picture a README can show:\n    $ click-extra snippet --output basket.svg basket.py\n\n\x08\n  Draw it as selectable text, under a named syntax style:\n    $ click-extra snippet --output basket.html --syntax-style dracula basket.py\n\n\x08\n  Number the lines and point at the one that matters:\n    $ click-extra snippet --output basket.svg --line-numbers --emphasize-lines 12 basket.py\n'¶

Sample invocations closing the snippet help screen.