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
--outputpoints.A bare
-prints it instead, seeis_stdout(), throughclick.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,--accessibleandNO_COLORreach a capture, sinceinvocation_color()carries the tri-state all four of them resolve to.
- click_extra.cli_capture.resolve_capture_format(output, fragment)[source]¶
Read the capture format off
--output, and settle--fragmenton it.Both capture commands carry the pair of options, so both carry the same rejection:
--fragmentasks for the bare block of a standalone document, and only HTML has one.- Parameters:
- Return type:
- Returns:
the format to render.
- Raises:
ClickException – on an extension no format claims, or on
--fragmentagainst anything but HTML.
- click_extra.cli_capture.capture_options(*, columns_help, default_columns=80)[source]¶
Attach every option the two capture commands share.
screenshotpictures what a command printed andsnippetpictures 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--backdropon 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
--helpprints. 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.
- 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
screenshothelp 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
snippethelp screen.