CLI screenshots¶
You can produce this screenshot of a git diff:
By invoking click-extra screenshot in your terminal, without installing it:
$ uvx click-extra screenshot --output git-diff.svg --preset macos -- git diff --color=always --no-index basket.txt basket.new.txt
The screenshot is written to an SVG file, where:
--output git-diff.svgnames the file to write.--preset macossets the window’s chrome to the macOS style.--separates those options from the command to capture.--color=alwayskeepsgitprinting colors even though its output is a pipe.--no-indexletsgit diffcompare two plain files instead of a repository.
Capture a command¶
The screenshot command¶
click-extra screenshot runs a command and writes its colored output to a file. Use -- to separate the screenshot options from the command’s own options:
$ click-extra screenshot --output cli-help.svg -- my-cli --help
$ click-extra screenshot --help
Usage: click-extra screenshot [OPTIONS] COMMAND_LINE...
Capture a command's colored output and write it as an image or HTML.
Runs COMMAND_LINE with colors forced on and its terminal width pinned, then
writes the captured output where --output points. Its extension picks the
format:
- .svg: a picture of a terminal window, for a surface that strips inline
HTML. A README on GitHub or PyPI has no other option;
- .html: selectable, searchable, copy-pasteable text, for a page you own.
Put -- before the command line so its own options are not mistaken for this
command's:
click-extra screenshot --output shot.svg -- my-cli --help
COMMAND_LINE is anything the shell can run, Click CLI or not. A Click CLI not
built on Click Extra prints its help uncolored, so --wrap routes it through
the wrap subcommand first and captures the colored rendering.
An SVG starts each run of text on its own column, so it renders correctly
outside a web browser, where a file manager, a git client or a thumbnailer
would otherwise slide the columns out of place.
Neither format needs an optional dependency.
--record runs the command under a pseudo-terminal instead, and writes an
animated SVG of every screen it drew: the frames a spinner, a progress bar or
a full-screen program asks a terminal for, which a plain capture never sees.
The invocation stands above the output as a shell prompt, and the loop pauses
on the final screen for as long as its line count asks, see --hold.
Options:
--output FILE Path of the file to write. Its extension picks
the format: .svg for an image, .html for
selectable text, .ansi for the escape sequences
themselves. Pass - to print those to the
terminal, which draws no window. [required]
--columns [auto|INTEGER] Terminal width, in characters, the command wraps
its output to and the image is laid out at. Pass
auto to pin neither: the command finds its own
width, and the image is laid out at the longest
line it printed, so nothing folds inside the
picture. [default: 80]
--background [dark|light] Terminal chrome the capture is drawn on, and the
palette its colors resolve against. Match it to
the theme the captured CLI renders with: a light-
background theme washes out on the dark default.
[default: dark]
--preset [linux|macos|plain|windows]
Terminal to draw the capture as: its window
decorations, palette, font and prompt sigil.
Anything stated alongside wins over it. Left out,
the capture keeps the renderer's own neutral
window.
--font FAMILIES Fonts the text is set in, best first and comma-
separated, like 'JetBrains Mono, Menlo'. The list
closes on monospace unless it names a generic
family. Defaults to the fonts of --preset, or to
the renderer's own.
--border COLOR Color of the frame drawn around the terminal
window, as CSS names it. Pass none to draw no
frame. Defaults to the one the chrome can show.
--border-width PIXELS Thickness of that frame, in pixels. [default: 1;
x>=0]
--radius PIXELS How round the window's corners are, in pixels.
Zero squares them. Defaults to 8, or to the
rounding --preset terminal draws. [x>=0]
--backdrop COLOR Color filling the image behind the window, margin
included, as CSS names it. Left transparent by
default, so the page shows through. [default:
none]
--shadow COLOR Color of the drop shadow lifting the window off
the page, as CSS names it. Pass none to draw no
shadow. Defaults to the one the chrome calls for.
--margin PIXELS Transparent pixels left around the window, on all
four sides. The room the drop shadow falls into,
so a capture drawing one wants some. [default:
48; x>=0]
--padding PIXELS Pixels added inside the window, around the drawn
text, on top of the few the renderer adds on its
own. [default: 8; x>=0]
--opacity FLOAT RANGE How solid the window's body is. Under 1 it turns
see-through, the way a terminal set to
transparency does: whatever the capture sits on
shows through it, while its text, frame and title
bar keep their own paint. [default: 1.0;
0<=x<=1]
--watermark TEXT Credit line drawn in the image's bottom-right
corner, in the margin around the window. Pass an
empty string to draw none, or your own text to
credit your project instead. [default: generated
with click-extra]
--watermark-color COLOR Color that credit line is drawn in, as CSS names
it, alpha included. Defaults to a neutral gray:
the line sits in the transparent margin, so it
answers to the page embedding the image rather
than to the chrome.
--head INTEGER RANGE Keep only the first N lines. [x>=1]
--tail INTEGER RANGE Keep only the last N lines. [x>=1]
--truncation [auto|TEXT] Line standing in for what --head or --tail cut
away, or auto to draw a rule across the width of
the picture. [default: auto]
--wrap-marker [auto|TEXT] Character closing each row a line wider than
--columns folds at, or auto for ↵. It takes a
cell of the row it closes. Left out, a line folds
silently, the way a terminal folds it. SVG only.
[default: ""]
--line-numbers Number the drawn lines in a gutter, the way
Pygments does inline. Line 1 is the first line
the picture shows.
--emphasize-lines LINES Draw a band behind the lines named, as 2,4-5.
Counted from 1 as the picture draws them. Ranges
are closed: state both ends.
--title TEXT Caption drawn in an SVG's window chrome, or an
HTML document's title. [default: ""]
--fragment For HTML, emit the bare block instead of a
standalone document, to paste into a page that
has its own.
--palette FILE Color scheme the captured colors resolve against,
read from a Windows Terminal scheme (.json) or an
iTerm2 one (.itermcolors). Replaces the palette
of --preset and --background, and leaves the
window they draw as it is. An HTML capture takes
its background and foreground alone.
--prompt TEXT Command line to display above the output, when it
differs from the one that is run. Pass an empty
string to draw no prompt at all. Defaults to the
command line itself.
--merge-stderr Fold the command's stderr into the capture, for a
CLI printing its help there. Off by default,
which is what keeps a wrapper's build chatter out
of the image.
--wrap Route COMMAND_LINE through the wrap subcommand,
so a Click CLI that is not built on Click Extra
is captured with its colors. Only works on a
target wrap can resolve.
--timeout SECONDS Seconds before the command is killed, counted
from its launch. Waits forever by default. With
--record, this also ends the recording, which
--end does on the clock of --start instead.
[x>0]
--record Run the command under a pseudo-terminal and write
an animated SVG of the screens it draws, spinners
and progress bars included. Needs an .svg
--output and a numeric --columns. Unix only.
--rows INTEGER RANGE With --record, the height of the terminal the
command runs in, in characters. Defaults to 24.
[x>=1]
--start SECONDS With --record, seconds of the recording to drop,
counted from the first screen the command draws:
the animation opens on the screen it showed then,
like a player told where to start. Defaults to 0.
[x>=0]
--end SECONDS With --record, where the recording stops, in
seconds after the first screen the command draws,
as --start counts them. The command is stopped
there too. [x>0]
--hold [auto|FLOAT] With --record, extra seconds the last frame stays
up before the animation starts over, or auto to
scale them to that frame's line count. Defaults
to auto.
--blank SECONDS With --record, seconds of empty screen closing
the cycle. Defaults to 0.6. [x>=0]
--cursor [auto|block|bar|underline]
Draw a terminal cursor where the command left it.
Bare, it takes the shape the --preset terminal
draws; name one to override that. Omitted, no
cursor is drawn.
--blink SECONDS With --cursor, seconds one blink takes. Pass 0 to
draw a steady cursor. Defaults to 1.0. [x>=0]
--closing-prompt / --no-closing-prompt
Draw the shell's prompt on the row under the
output, where it comes back once the command
exits. Costs no height alongside --cursor, which
already leaves that row for the cursor to wait
on. [default: no-closing-prompt]
--typing SECONDS With --record, open the animation by typing the
command line out, this many seconds per
character. Omitted, the prompt stands there from
the first frame. [x>0]
--submit SECONDS With --typing, seconds the finished command line
waits before its output starts. Defaults to 0.4.
[x>0]
--speed FLOAT RANGE With --record, how much faster to play than
recorded: 2 halves every frame's time. Defaults
to 1.0. [x>0]
-h, --help Show this message and exit.
Configuration options:
--config LOCATION Location of the configuration file. Supports
local path with glob patterns or remote URL.
[default: ~/.config/click-extra/]
--no-config Ignore all configuration files and only use
command line parameters and environment
variables.
--validate-config LOCATION Validate the configuration file and exit.
--export-config FORMAT Export the configuration in the selected format
to <stdout>, then exit.
Output options:
--accessible Accessibility mode: disable colors and render
tables in a borderless, screen-reader-friendly
format.
--color [auto|always|never] Colorize the output. A bare --color is the same
as --color=always. [default: auto]
--no-color Disable colorization (alias of --color=never).
--progress / --no-progress Show progress indicators during long operations.
Disabled for non-interactive output (pipes, dumb
terminals, CI) and by --accessible. [default:
progress]
--theme [auto|dark|dracula|light|manpage|monokai|nord|solarized-dark]
Color theme used for help screens. [default:
dark]
--table-format FORMAT Rendering style of tables. [default: rounded-
outline]
Logging options:
--verbosity LEVEL Either CRITICAL, ERROR, WARNING, INFO, DEBUG.
[default: WARNING]
-v, --verbose Increase the default WARNING verbosity by one
level for each additional repetition of the
option. [default: 0]
-q, --quiet Decrease the default WARNING verbosity by one
level for each additional repetition of the
option. [default: 0]
--debug Shorthand for --verbosity DEBUG.
Introspection options:
--time / --no-time Measure and print elapsed execution time.
[default: no-time]
--params Show all CLI parameters, their provenance,
defaults and value, then exit.
--tree Show the tree of nested subcommands and exit.
--man Read the command's manual page and exit.
--help-format [carapace|json|json-full|man|markdown|markdown-full]
Render the command in the given format and exit.
--version Show the version and exit.
Examples:
Draw a help screen as a picture a README can show:
$ click-extra screenshot --output my-cli.svg -- my-cli --help
Draw it as selectable text, for a page you own:
$ click-extra screenshot --output my-cli.html -- my-cli --help
Capture a CLI that is not built on Click Extra, colored all the same:
$ click-extra screenshot --output flask.svg --wrap -- flask run --help
Record the frames a spinner draws, as an animation:
$ click-extra screenshot --output ripen.svg --record --columns 80 -- ripen
It settles three things a general capture tool leaves to you:
Colors. A command strips colors as soon as its output is a pipe. The capture runs under
click_extra.color.forced_color(), which setsFORCE_COLORand clears anyNO_COLORin the environment.Width.
--columnssets what the command wraps to and what the image is drawn at. If the two disagree, the rendered lines overrun the image.stderr. It stays out of the capture unless--merge-stderrasks for it, which keeps a wrapper’s build chatter out of the picture.
SVG or HTML¶
The extension of --output selects the format:
Format |
Text is |
Goes where |
|---|---|---|
|
a picture |
a surface that strips inline HTML: a README on GitHub or PyPI |
|
selectable, searchable, copyable |
a page you own: your site, a blog post, a slide deck |
GitHub and PyPI render SVG as an image and strip inline styling, so a README needs SVG, and the capture’s text becomes pixels there: no page search, no copy. Where you control the markup, HTML keeps the text as text, so a reader can find a flag with the page’s own search and copy it straight into a terminal.
Neither format needs an optional dependency.
$ click-extra screenshot --output cli-help.html -- my-cli --help
That writes a standalone document. Add --fragment to get the bare <pre> and the credit line under it, both styled inline, so the page they are pasted into needs no stylesheet.
Tip
An SVG capture needs no web font and no HTTP request to render, so it draws the same in any viewer that implements the whole of SVG’s text styling.
Caution
Not every viewer does. macOS has two SVG engines, and they disagree. Preview, Quick Look and Safari go through WebKit and draw a capture in full. Finder’s icon thumbnails and any app reading the file through NSImage go through Core Graphics instead, which implements fill and font-weight but neither font-style nor text-decoration: italic renders upright and underline, overline and strikethrough render as nothing. Colors, bold, dim and reverse survive.
The file is the same either way, so there is nothing to fix in a capture that looks flat in a file manager or a git client. Open it in a browser to see what a reader on a documentation page gets. Animated captures and OSC 8 hyperlinks reach no static thumbnail at all, whichever engine draws it.
Note
HTML has two limitations SVG does not. An OSC 8 hyperlink loses its URL and keeps its visible text. The eight base ANSI colors render as their CSS names, so the browser’s palette decides their shade, not the terminal’s. Neither shows up on a help screen, which is why the format is worth having anyway.
Straight to the terminal¶
--output - draws no window and prints the captured escape sequences, so you can see what a capture holds before committing it to a file. --output shot.ansi writes the same thing out.
$ click-extra screenshot --output - -- my-cli --help
The escapes are dropped when the destination turns out to be a pipe, unless --color=always keeps them. Nothing describing a window applies here, so the frame, the chrome and the credit line are all ignored.
See also
To picture source code instead of a command’s output, see code snippets. Both are drawn in the same window, and the whole styling vocabulary below applies to either.
Any command, any CLI¶
screenshot runs anything the shell runs, Click CLI or not. git --help and docker ps capture as readily as your own tool. The file holds exactly what the command prints, so a Click CLI not built on Click Extra lands in it uncolored.
To capture it with colors, run it through wrap first. wrap patches Click’s help rendering without touching the target’s code. --wrap does that for you:
$ click-extra screenshot --output flask-help.svg --wrap -- flask --help
This is shorthand for composing the two commands by hand:
$ click-extra screenshot --output flask-help.svg --prompt "click-extra wrap -- flask --help" -- click-extra wrap -- flask --help
The prompt line shows the wrap invocation, not the bare command. The wrap invocation is what reproduces the colored screen: flask --help on its own prints the plain one.
--prompt also stands on its own. It draws its text as the command line above the output. Use it when the invocation you ran is not the one the reader should type.
Note
wrap decides how a CLI renders, and reaches only the Click commands it can import. screenshot decides where the output goes, and reaches anything executable. Composing the two covers the overlap. This is also why --wrap insists on the installed click-extra command rather than falling back to python -m click_extra: the two resolve a target differently, so the fallback would quietly capture a different CLI.
Style the capture¶
Width¶
--columns pins the width twice: the command wraps its output to it, and the image is laid out at the same width. The two must agree, or the rendered lines overrun the picture.
--columns auto pins neither. The command finds its own width (the terminal it runs in, or Click’s default of 80 through a pipe). The image is laid out at the longest line that came back:
$ click-extra screenshot --output params.svg --columns auto -- my-cli --params
Use it when the output holds a line the command does not wrap on its own: a long invocation drawn as the prompt, a wide table, a machine-readable dump. A pinned width folds such a line mid-word. The trade-off: the picture stops being a fixed-width terminal, so captures meant to sit side by side should name a width instead.
Marking a fold¶
A terminal folds a line wider than itself without a mark, so a picture of one cannot tell a folded line from one the command printed in two pieces. A break that lands mid-word then reads as a typo. --wrap-marker auto closes each folded row on ↵, the symbol delta draws for the same purpose:
$ click-extra screenshot --output report.svg --columns 100 --wrap-marker auto -- my-cli report
The marker is drawn in the gray of the truncation rule, so it reads as a mark of the picture and not as output. It takes the last cell of the row it closes: a line exactly as wide as --columns fits without a marker and folds with one. Any other text is taken as the marker itself, like ¬. Left out, a capture folds silently, the way the terminal it pictures does.
The marker applies to SVG captures only. An HTML capture reflows with its page, and a terminal reading ANSI folds on its own. A recording is refused it too: its pseudo-terminal already folds every line, so its screens hold no fold to mark.
A long invocation¶
The prompt is a line like any other, so it counts toward the picture’s width. A script passed inline is the usual cause: the command line ends up longer than anything it prints. --columns auto then lays the image out at the invocation instead of at the output, and a pinned width folds that invocation across several rows.
--prompt settles it. It states the line a reader would type, in place of the one that ran:
$ click-extra screenshot --output market.svg --prompt "python market.py" -- python -c 'print("苹果 apple")'
Only the drawn line changes. The capture still holds what the inline script printed, so the image is laid out at that output alone. This is the same option a foreign CLI uses to hide the wrapper it was reached through.
Each argument is quoted as a shell needs it, so the drawn line pastes back as the command it pictures. An argument holding a space stays one argument, rather than spilling into the line as several.
--prompt "" draws no prompt at all. Reach for it when the prose around the capture already carries the command. A documentation block spells that one :hide-prompt:.
Light and dark chrome¶
A capture freezes the colors of the run it shows, so the window must match the theme that run rendered for. --background light swaps the dark chrome for white, along with the ANSI palette the capture’s colors resolve against:
$ click-extra screenshot --output light-help.svg --background light -- my-cli --theme light --help
Both halves are needed, and they are different halves: --theme light is what the CLI renders with, --background light is what the image is drawn on. Pass one without the other and you get the washed-out screen the theme gallery warns about.
The prompt line follows the chrome on its own. It is the one line a capture draws rather than collects, so on white it would otherwise vanish in the dark theme’s near-white invoked_command style.
A CLI that asks gets the same answer. A capture states its chrome to the command the way a terminal would, through the CLITHEME and COLORFGBG variables that background detection reads. A CLI with --theme auto then renders for the window it lands in:
$ click-extra screenshot --output light-help.svg --background light -- my-cli --theme auto --help
Here is that at work on one of click-extra’s own help screens. The two images below came from the same command line, --background apart. The CLI picked its palette from the terminal each capture claimed to be:
$ click-extra screenshot --output docs/assets/auto-theme-dark-screen.svg --prompt "click-extra --theme auto themes --help" -- uv run --frozen -- click-extra --theme auto themes --help
$ click-extra screenshot --output docs/assets/auto-theme-light-screen.svg --background light --prompt "click-extra --theme auto themes --help" -- uv run --frozen -- click-extra --theme auto themes --help
auto is not the default, on purpose. A CLI that never asks for it keeps rendering exactly as it does everywhere else. That is why the examples below spell out --theme dark and --theme light rather than rely on detection.
Here is one help screen taken both ways, with the CLI’s theme and the image’s chrome moving together:
Both blocks hide their results, an exception to what :screenshot: is usually for. A results block on this page takes its colors from the site’s stylesheet and follows the reader’s own theme, so it cannot show the one thing being compared here.
The window¶
A capture is drawn as a terminal window: a rounded rectangle, framed with a border and lifted off the page by a drop shadow. Every part of it is an option:
$ click-extra screenshot --output shot.svg --title "my-cli --help" --backdrop "#1f6feb" --radius 0 --border-width 2 --margin 28 -- my-cli --help
Option |
Takes |
Default |
Draws |
|---|---|---|---|
|
CSS color |
the chrome’s |
The frame around the window. |
|
pixels |
|
How thick that frame is. |
|
pixels |
|
How round the window’s corners are. |
|
CSS color |
the chrome’s |
The drop shadow under the window. |
|
CSS color |
none |
A page behind the window, margin included. |
|
pixels |
|
Transparent space around the window. |
|
|
|
How solid the window’s body is. Under |
|
text |
the click-extra credit |
A credit line in the image’s bottom-right corner. Empty draws none. |
|
CSS color |
a neutral gray |
The ink that line is drawn in. |
|
pixels |
|
Space inside it, on top of the renderer’s own. |
|
flag |
off |
A dim gutter numbering the captured lines. |
|
text |
none |
A caption centered in the window’s title bar. |
Two of them default to the chrome’s own value rather than a fixed one. That is why they are not constants: a fixed translucent white would make a light capture a white window on a white page, with no visible edge.
The rest depend on what the capture is for. A shadow needs --margin to fall into, because the image’s own box cuts whatever lands past it. --backdrop fills that same space instead of leaving it transparent, which turns a capture into a self-contained picture for a slide or a social card. --radius 0 drops the desktop-window look, for a capture meant to read as a plain block of output.
Both formats take the same options. An HTML capture lands them on the block’s border, border-radius, box-shadow, margin, padding and the page’s background.
Tip
A shadow is an SVG filter. Some renderers skip filters, but they still draw the border, so the window keeps an edge either way.
Gradients¶
--backdrop also takes a CSS gradient, which gives a capture its own page:
$ click-extra screenshot --output card.svg --backdrop "linear-gradient(135deg, #667eea, #764ba2)" -- my-cli --help
Understood are linear-gradient, opening with an angle (135deg) or a side keyword (to bottom right), and radial-gradient. Both take two or more color stops, each pinnable at a percentage (#667eea 30%). Anything else is treated as a plain color. HTML captures pass the value through to CSS untouched.
Transparency¶
--opacity makes the window’s body translucent, the way a terminal set to transparency does. Below 1, whatever sits behind the capture shows through, while its text, frame and title bar keep their own paint:
$ click-extra screenshot --output glass.svg --opacity 0.7 --backdrop "linear-gradient(135deg, #667eea, #764ba2)" -- my-cli --help
Over a backdrop it reads as frosted glass: the gradient tints the terminal instead of stopping at its edge. With no backdrop, the page shows through, which is what a capture dropped on a surface you do not control wants. What limits the value is legibility: a body much under half solid gives the text whatever contrast the backdrop happens to have.
An HTML capture thins the block’s background color with CSS color-mix(), so the page it is pasted into shows through the same way.
Line numbers¶
--line-numbers draws each line’s number in a dim gutter, the way Pygments does inline. Line 1 is the prompt:
$ click-extra screenshot --output numbered.svg --line-numbers -- my-cli --help
The numbers land in the terminal text rather than in a column of their own, the same trade Pygments makes: every renderer places them for free, and a reader copying an HTML capture copies them too.
It also means the gutter spends columns the command already used: a screen wrapped at 80 comes back a few characters too wide and folds. Pair the flag with --columns auto, or with a width that leaves room for the gutter, so the image grows instead of the lines breaking.
Emphasized lines¶
--emphasize-lines draws a band behind the lines it names, the way Pygments marks a highlighted line in a code block. Line 1 is the prompt, the same line the gutter counts first:
$ click-extra screenshot --output marked.svg --emphasize-lines 2,4-5 -- my-cli --help
The band is mixed from the chrome it is drawn on rather than stated outright, so one setting serves both: a shade lighter than a dark terminal, a shade darker than a light one. It runs from one edge of the window to the other, because what is emphasized is the row, not the column of text in it. It sits behind the text and follows the window’s own rounding, so a band on the last line cannot square off the corners.
Lines are counted on the canvas, blanks included, the way a gutter numbers them. Turn :screenshot-line-numbers: on while choosing them and the two counts agree.
Ranges on the command line are closed, so state both ends: the capture’s height is only known once the command has run, too late for 4- to mean anything. Inside a documentation block the height is known, so :screenshot-emphasize-lines: takes the open-ended form too.
An animated capture bands the same way, one frame at a time. A band appears with the frame that first draws the row it marks, and it is gone wherever the row is. The empty beat closing a cycle carries none: banding a row before the animation reaches it would read as a stray rectangle in blank space.
The credit line¶
Every capture the command writes carries a credit line in the margin at its bottom-right corner. Here is one, reading generated with pantry 1.4.2:
By default, the line names click-extra. A capture needs that once it has travelled: on a slide, in a README or on a social card it sits far from the page that explains where it came from. The line names no release: a capture is committed beside the project that drew it and regenerated at every release, and a release number would rewrite every asset on release day. --watermark replaces the text, and an empty string draws none:
$ click-extra screenshot --output shot.svg --watermark "pantry 1.4.2 · example.com" -- my-cli --help
$ click-extra screenshot --output shot.svg --watermark "" -- my-cli --help
Crediting your own project rather than the tool that drew it is the expected case, not an exception. Set it once in your configuration file and every capture carries it.
Whatever the credit line says, the source of an SVG capture holds a comment that names the tool and its repository: <!-- @generated by Click Extra <https://github.com/kdeldycke/click-extra> -->. An empty credit line leaves that comment in place.
The mark is the one thing drawn outside the window, so it is also the one paint that cannot follow the chrome: the margin is transparent, and behind it sits a page this command never sees. Hence a neutral gray, which reads on a white README and a dark one alike. --watermark-color covers a capture whose backdrop it has to sit on.
A capture written by a click:run block carries no watermark by default: the page around it already says what drew it. :screenshot-watermark:, or the click_extra_screenshot_watermark conf.py value, turns it on for a project that wants it anyway.
All of it at once¶
Here is the pantry screen again, wearing every option above: on a gradient, captioned, numbered, rounded, padded, see-through enough for the gradient to tint it, and with its Options: heading and its --crates entry picked out. The second tab shows the block that wrote it:
```{click:run}
:screenshot: styled-window-screen
:screenshot-columns: auto
:screenshot-title: 🍎 pantry --help
:screenshot-backdrop: 'linear-gradient(135deg, #667eea, #764ba2)'
:screenshot-emphasize-lines: 6,12-13
:screenshot-line-numbers:
:screenshot-opacity: 0.75
:screenshot-radius: 12
:screenshot-padding: 24
:hide-results:
result = invoke(pantry, args=["--help"])
assert result.exit_code == 0
assert "--crates" in result.stdout
```
A caption takes any text a terminal can draw, emoji included. :hide-results: is this page’s choice, since the window is the thing on show: leave it out and the block renders its live text below the fence as well.
None of that is limited to the still. An animated capture is drawn through the same window, so it carries the gradient, the caption, the rounding, the transparency and the gutter exactly as a screenshot does. Here is a pantry being restocked, wearing everything above:
The gutter counts each frame’s own rows, so it grows as the trail does, and the band on the third line arrives on the same frame its number does. It keeps the width of the tallest frame throughout, so no row moves when the count reaches 10.
Terminal presets¶
A capture is a picture of a terminal, and terminals do not look alike. --preset styles the window as a named desktop’s terminal:
$ click-extra screenshot --output shot.svg --preset windows -- my-cli --help
Each preset carries the five things that make a terminal recognizable: its window decorations, the palette its colors resolve against, the font it ships with, the prompt sigil of its usual shell, and the shape of its cursor. An option stated alongside wins, so --preset windows --radius 8 rounds the corners Windows squares.
A preset also paints the strip its buttons and caption sit in, a shade off the terminal’s own background, because that strip belongs to the desktop. That makes plain the odd one out: it mimics no desktop, wears no buttons, and drops the strip entirely unless a --title gives it something to hold.
Each tab below shows its preset twice: bare, and then wearing everything else this page offers. The second picture states no --radius, so each terminal keeps its own corners: Windows stays square under the same gradient that rounds the other three.
Transparency lands least alike across them, because each preset brings its own background for the gradient to show through. At 75% it barely lifts Apple Terminal’s black and visibly lifts GNOME’s lighter #2e3436. All four still clear WCAG AA for their text, from 14.4:1 down to 6.4:1, so what changes is the character of the window, not whether it can be read.
Round buttons on the left, Apple’s Pro and Basic palettes, SF Mono, and a $ prompt.
Minimize, maximize and close on the right, square corners, the Campbell and One Half Light schemes, Cascadia Code, and a PS C:\> prompt.
A single close button, the Tango palette GNOME Terminal ships, Ubuntu Mono, and a $ prompt.
No buttons, no rounded corners, no title bar: for a capture that has to read as a block of output rather than as a window, on a slide or in a paper.
Caution
A preset’s palette is the scheme its terminal ships with, not the one your reader configured. It also decides how the captured CLI’s colors land: a screen rendered for a dark theme on a light preset washes out, exactly as the chrome section describes.
Your own colors and font¶
A preset brings the colors and the font its terminal ships with. --palette and --font replace them with the ones your own terminal uses, and leave the window as the preset draws it:
$ click-extra screenshot --palette orchard-night.json --font "JetBrains Mono, Menlo" --output shot.svg -- my-cli --help
--palette reads a color scheme file in one of the two formats schemes are most often shared in: a Windows Terminal scheme (.json) or an iTerm2 one (.itermcolors). iTerm2-Color-Schemes publishes hundreds of schemes in both. A scheme states the background and the 16 colors a CLI names, so pair a light one with --background light, which also tells the CLI to render for a light terminal.
--font takes font families, best first and comma-separated. A capture embeds no font, so a reader without the first family gets the next one. The list closes on monospace unless it names a generic family itself.
Note
An HTML capture takes the scheme’s background and foreground alone. The eight base colors render as their CSS names there, see SVG or HTML.
Wide glyphs and writing systems¶
A terminal cell is not a character. A Chinese ideograph, a Hangul syllable, a fullwidth Latin letter and most emoji are each drawn two cells wide, while a combining accent is drawn in none at all. A capture measures its runs in cells, through click_extra.layout.cell_width(), which is the same wcwidth measurement click-extra already uses to align tables and the command tree.
The CLI below pads with that measurement, so every name lands on column 12 whatever script precedes it:
from click_extra import command, echo
from click_extra.layout import cell_width
FRUITS = (
("苹果", "apple"),
("バナナ", "banana"),
("체리", "cherry"),
("KIWI", "kiwi"),
("🍎🍌🍒", "basket"),
("┌──┬──┐", "crate"),
("مشمش", "apricot"),
)
@command
def market():
"""List each fruit beside its name, aligned on a fixed column."""
for glyphs, name in FRUITS:
echo(f"{glyphs}{' ' * (12 - cell_width(glyphs))}{name}")
$ market
苹果 apple
バナナ banana
체리 cherry
KIWI kiwi
🍎🍌🍒 basket
┌──┬──┐ crate
مشمش apricot
Size a run by its character count instead and the picture drifts: the seven lines above would land on four different columns, the wide scripts drawn at half their width and stacking on each other. That is rich#2742, open upstream since 2023 and one of the reasons this renderer is click-extra’s own. The upstream page collects the rest.
Two spaces are what mark a column. A capture cuts each line at its gutters (click_extra.capture.svg.column_segments()), then pins every piece to its own offset. One space is ordinary word spacing rather than a gutter, so a wide glyph and the word after it stay a single run, and where that word sits inside the run is left to the font. Pad a column to a fixed width, the way market does above, instead of separating it by one space. Captured output rarely trips on this: a table or a help screen already leaves two spaces or a rule between its columns. A hand-written example is where it shows.
Note
Right-to-left scripts are the case cell arithmetic cannot settle. Arabic and Hebrew are reordered by whoever draws them, and the cursive ones are shaped: a letter’s form depends on the letters it joins. A run carrying any of them is therefore left to size itself, rather than pinned to an exact width that would pay for the difference in letter spacing and pull the word apart at its joins. The run still starts on its own column, so the grid around it holds; only its own width floats.
Box-drawing characters are not letters but tiles: a table’s rule and a tree’s elbow are drawn by butting them edge to edge. As glyphs, two adjacent tiles meet wherever the font and the renderer place them, a fraction of a pixel off the grid, which shows as a seam or a kink at every join: that is rich#2536, where the answer upstream is that it would take replacing the characters with drawn shapes. A capture does that, the way terminals draw these characters: each is the lines it names, from its cell’s edge to its middle, and a rule running across cells is one line.
Block elements, from ▀ to ▟, are drawn as shapes too: each is the rectangles it names, filling its share of the cell. A font draws them shorter than a capture’s row, so as glyphs, two stacked rows of block art would leave a band of background between them. Braille patterns, from U+2800 to ⣿, are drawn as the dots they raise, on one even grid across cells: Menlo has no Braille, and the font a reader falls back to draws it wider than a column. An SVG capture draws these shapes with <rect>, <path> and <circle> elements, an HTML capture with CSS backgrounds and, for box drawing, an inline SVG. The characters stay in the text, unpainted, so copying a capture’s text still returns them. See click_extra.capture.svg.BOX_ARMS, click_extra.capture.svg.BLOCK_ELEMENTS and click_extra.capture.svg.BRAILLE_DOTS.
Animate a capture¶
Animated captures¶
An SVG capture can hold more than one frame. Pass frames a sequence of captured texts and interval how long each is shown. The window and its caption are drawn once, and every frame is stacked inside them.
from pathlib import Path
from click_extra.capture.svg import render_svg
from click_extra.spinner_presets import SPINNERS
from click_extra.styling import Style
preset = SPINNERS["moon"]
lemon = Style(fg="#f1fa8c")
Path("brewing.svg").write_text(
render_svg(
columns=34,
title="brewing",
unique_id="brewing",
frames=[lemon(f"{frame} brewing tea…") for frame in preset.frames],
interval=preset.interval,
),
encoding="UTF-8",
)
One number for interval times every frame alike, which is what a spinner asks for. A sequence gives each frame its own, which is what a recording asks for.
The frames differ in nothing but their text, so one stylesheet covers all of them. Everything is namespaced by unique_id, keyframes included, so two animations inlined into one page keep their own timing.
A piece several frames draw alike, a background or a run of text, is drawn once and shown over each of those frames. A recording redraws its whole screen many times a second, and most of that screen stays put: drawn once, it costs one copy, not one per frame.
One frame stays visible wherever the animation does not run, so a capture is never a blank rectangle. The capture also honors a system asking for reduced motion, by keeping every animation rule behind a prefers-reduced-motion guard.
A recorded animation also pauses on its last frame and then closes on an empty beat. A loop restarting the instant it arrives gives a reader no time to read the end. The empty beat says plainly where the loop comes round.
Three knobs state all of it, on render_svg, on the --record command line and on a documentation block alike:
|
CLI |
Directive |
What it sets |
|---|---|---|---|
|
|
|
Extra seconds on the last frame, or |
|
|
|
Seconds of empty screen closing the cycle. |
|
|
|
How much faster to play than recorded: |
speed scales the replay only. The two pauses are stated in real seconds and stay untouched. A declared spinner cycles in place and ends nowhere, so it holds and blanks for nothing unless a page asks.
hold also takes auto, which scales the pause to the final frame itself: a quarter second per populated line, clamped between 2 and 30 seconds. A fixed number serves an ending the author has seen; auto serves one that changes with every retake, like a recorded command whose closing report grows with what there is to report. A :screenshot-record: block and a --record capture therefore default to it, and a stated number overrides it.
The frame left visible is the last one, because an animation that accumulates says most once it has finished. An animated capture is therefore always a still as well.
A blinking cursor¶
A capture draws no cursor unless it is asked for one. Pass a Cursor and it draws one:
from click_extra.capture.presets import Cursor, CursorShape
from click_extra.capture.svg import render_svg
render_svg("$ pantry restock --crates 4", columns=44, cursor=Cursor())
Where the cursor stands is never stated: it is read off each frame’s own text. A screen ends with whatever was written to it last, so the cursor sits after that. Output closing on a newline puts it on the row underneath, and the window grows a line to hold it, the way a terminal’s does.
Three fields say what it looks like:
Field |
What it sets |
|---|---|
|
|
|
Seconds one blink takes. |
|
Paint it is drawn with. |
A preset names the shape its terminal draws, so --preset windows gets Windows Terminal’s bar and the rest get a block. Cursor(CursorShape.BAR) overrides that.
The blink runs on a clock of its own rather than on the animation’s. The two drift against each other across a loop, which is what a terminal showing a cursor over a running command looks like.
Caution
Blinking is motion. The rule sits behind the same prefers-reduced-motion guard as every other animation here, so a reader who asked their system for less of it gets a cursor that is lit and still.
A still capture takes a cursor too, and leaves it after the last thing the command printed, which is where the shell finds it. :screenshot-cursor: asks a documentation block for one, and :screenshot-blink: says how fast. A block draws its own invocation already:
The cursor sits on the row under the output, because the command’s last line ended on a newline. That is where a terminal leaves it, so the window grows a line to hold it.
The shell coming back¶
A command exits and the shell prints its prompt again. --closing-prompt, and :screenshot-closing-prompt: on a documentation block, draw that last row:
Alongside a cursor it is free. Output ending on a newline already leaves the row the cursor waits on, and the sigil fills it instead of leaving it blank. A command that never ended its line is given one, exactly as a shell prints its own newline before prompting.
An animation closes its last frame and no other. The shell has not come back while the command is still drawing, and a sigil on an earlier frame would say it had.
Recording an animation¶
The frames above were declared. They can also be recorded, from a command that draws them.
This is the one thing a pipe cannot capture. A spinner asks whether its stream is a terminal and stays silent when it is not, so a command run the ordinary way prints its result and none of the frames leading to it. Forcing color through the environment does not help, because that answers a different question.
For a spinner this process hosts, hand it a ScreenRecorder. It claims to be a terminal without being one, so no pseudo-terminal is involved and it works on every platform:
from click_extra import SPINNERS, Spinner
from click_extra.capture.recording import ScreenRecorder
recorder = ScreenRecorder()
with Spinner("Brewing tea", spinner=SPINNERS["moon"], stream=recorder):
steep()
frames = recorder.frames()
For a command this process does not host, record_command runs it under a pseudo-terminal and reads both its output and its errors, the spinner drawing on the latter:
from click_extra.capture.recording import record_command
frames = record_command(("kettle", "boil", "--slowly"), columns=60, duration=5.0)
That path is Unix only: a pseudo-terminal is termios and pty, neither of which Windows ships, and reaching ConPTY would mean a dependency. The in-process recorder above covers Windows.
Each Frame carries the screen it held and how long it held it, so render_svg takes them directly:
render_svg(
columns=60,
frames=[frame.text for frame in frames],
interval=[frame.duration for frame in frames],
)
Caution
A recording is timed by the wall clock, so the same command records slightly different durations every run. That is fine for a one-off image, and a problem for a committed one that every build redraws: see keeping a recording committable.
Type the command first¶
A recording holds what a command drew and never the invocation that drew it, so an animation opens on output arriving from nowhere. typing types the command line out first, one character per frame:
from click_extra.capture.presets import Cursor
from click_extra.capture.recording import record_and_render
svg, returncode = record_and_render(
("pantry", "restock", "--crates", "4"),
columns=44,
typing=0.05,
submit=0.45,
cursor=Cursor(),
)
typing is how long a character takes to appear, and submit is the beat the finished line waits before the output starts, which is the pause before the return key. Leave typing out and the prompt stands there from the first frame, which is what a recording shows without it.
The typed screens are ordinary frames. Everything the picture does for a frame therefore reaches them: a gutter numbers them, and the cursor walks along the line with no caret of its own to state.
For an animation assembled by hand, type_line makes those frames from a prompt line and nothing else:
from click_extra.capture.recording import type_line
opening = type_line("$ pantry restock --crates 4", typing=0.05)
A documentation block asks for the same with three options. :screenshot-prompt: states the invocation to draw, :screenshot-typing: types it, and :screenshot-submit: sets the beat before the output starts:
The cursor walks the line as it is typed, then drops to the spinner it started. Nothing states that: the cursor is read off each frame’s text, so it follows whatever the frame last drew.
Tip
A typed opening costs one frame per character. Those frames differ by a single character each, so they compress to almost nothing over the wire: the raw file roughly doubles while the gzipped one grows about a kilobyte.
Keeping a recording committable¶
Every build redraws a committed capture and writes it when it changes, which keeps it from drifting away from the CLI. A recording cannot live that way, and not because of its timings: the scheduler decides which spinner glyph pairs with which screen, so the same command records a different set of frames on every other run. Rounding the durations with quantize settles the jitter but cannot touch that.
So a recording is written once and then kept. :screenshot-record: writes the asset the first time and leaves it alone afterwards. It does not even evaluate its expression once the file exists. To take a fresh recording, delete the file and build again.
A recording states what it pictures on a line beside the generator tag:
<!-- @generated by Click Extra <https://github.com/kdeldycke/click-extra> -->
<!-- @recording frames=43 period=6.28s digest=778e48eddb9c2ae7 -->
The digest covers the frames a cycle holds and the beat it holds them on, not their order or their count.
Caution
Written once means frozen: nothing re-checks a recording against the code it pictures, so it rots the way any hand-made screenshot does. A declared animation has no such problem, being composed rather than timed, and is regenerated on every build like every other capture.
Recording from the command line¶
--record turns the screenshot command into a recorder: the command runs under a pseudo-terminal, so a spinner or a progress bar draws the frames it would draw for you, and every screen it leaves behind lands in one animated SVG.
$ click-extra screenshot --record --output recorded-trail-screen.svg -- click-extra trail
--cursor and --typing turn a recording into a session: the command line types itself at the prompt, a cursor follows it along, and the output arrives underneath.
$ click-extra screenshot --record --cursor --closing-prompt --typing 0.05 --columns 46 --output typed-trail-screen.svg -- click-extra trail
--cursor on its own takes the shape the --preset terminal draws, and --cursor bar or --cursor underline overrides it. --blink 0 leaves the cursor lit and still. Both apply to a still capture as well, where the cursor lands after the last thing the command printed.
The invocation stands above the output as a shell prompt, exactly as a still capture draws its own, and --prompt overrides or hides it the same way. --rows states the terminal’s height, --timeout stops a recording that would run on, and the pacing knobs above apply as given. Two of a still capture’s arrangements do not carry over: the width must be a number, since the pseudo-terminal exists before the command draws its first line, and --head/--tail stay out, a recording being made of whole screens.
Caution
Unix only, for the reasons record_command() states. The same pipeline is scriptable through record_and_render().
Full-screen programs¶
A program drawing on the whole terminal records the same way, like a dashboard or a system monitor. State the size it lays itself out for, and stop the recording with --end when the program waits for a key to quit:
$ click-extra screenshot --record --columns 100 --rows 50 --end 12 --hold 2 --output dashboard.svg -- orchard --dashboard
Each frame is the whole screen, at the height --rows states. The prompt the command was typed at stays underneath, covered by the program’s alternate screen as on a terminal. --closing-prompt draws nothing over a program stopped while its screen is still up.
--start drops the first seconds of a recording, which a program often spends filling its screen, like a profiler gathering its first samples. --end stops the recording, and the program, at a time on the same clock. Both count from the first screen the program draws, so --start 6 --end 10 keeps the four seconds between them. --timeout counts from the launch instead, and still stops a program that never draws a first screen. A :screenshot-record: block takes :screenshot-start: and :screenshot-end:, see start_at() and end_at().
Such a program writes the sequences its terminal’s terminfo entry lists, so the recording names one to it: TERM is RECORDING_TERM, whatever terminal the recording runs from. TerminalScreen reads that vocabulary, cursor addressing, scroll regions and line drawing included. A screen is noted once the program has been quiet for REDRAW_GAP, so a redraw arriving in several reads never shows half-drawn.
Caution
--cursor draws the cursor after the last row, wherever the program left it and whether it hid it or not. A query the program sends its terminal goes unanswered, so a program waiting for a reply waits until it gives up.
Publish and maintain¶
Stating a default once¶
screenshot is itself a Click Extra CLI, so every option above is also a configuration key. To draw every capture the same way, state it once in the pyproject.toml click-extra finds by walking up from the working directory:
[tool.click-extra.screenshot]
preset = "macos"
margin = 64
opacity = 0.85
watermark = "pantry 1.4.2 · example.com"
Any dedicated configuration file does the same under a [click-extra.screenshot] table. A flag on the command line still wins over both, following the usual precedence, so a single capture can break the house style without editing anything.
In Sphinx documentation, click:run blocks write the captures rather than the command, so the same setting is a conf.py value:
click_extra_screenshot_preset = "macos"
It covers every block whose :screenshot: names no preset of its own, leaving :screenshot-preset: for the pages that depart from it. A project keeping its settings in one place can read the value back out of its pyproject.toml, conf.py being Python:
import tomllib
from pathlib import Path
pyproject = tomllib.loads(Path("../pyproject.toml").read_text(encoding="UTF-8"))
click_extra_screenshot_preset = pyproject["tool"]["click-extra"]["screenshot"]["preset"]
Keeping captures fresh¶
Here is the command pointed at click-extra itself. Its bundled CLI doubles as a live demo of the rendering features. Each image below was produced by the line printed under it, run from a checkout.
gradient puts 24-bit ramps next to their 256-color quantized equivalents, so the stepping the smaller palette introduces is there to see:
$ click-extra screenshot --output docs/assets/color-gradient-screen.svg --prompt "click-extra gradient" -- uv run --frozen -- click-extra gradient
styles crosses every color with every text style. Its table wants far more than 80 columns, so the capture is taken at the width it actually needs:
$ click-extra screenshot --output docs/assets/text-styles-screen.svg --columns 160 --head 14 --prompt "click-extra styles" -- uv run --frozen -- click-extra styles
themes renders a sample help screen under each built-in palette, and this capture keeps the first two of them, which is what --theme does to a screen:
$ click-extra screenshot --output docs/assets/theme-gallery-screen.svg --head 34 --prompt "click-extra themes" -- uv run --frozen -- click-extra themes
--prompt makes each image show the bare click-extra … a reader would type, while uv run --frozen -- is what actually ran. The plumbing that reaches a checkout’s copy of the CLI is not worth picturing. --head bounds the two long ones, and a dotted rule closing on ✂ says the rest was cut.
The rule crosses the whole window, as the cut does: it spans --columns, less the cell a --wrap-marker takes and the gutter --line-numbers draws. Under --columns auto the picture is as wide as its widest line, prompt included, and the rule spans that width.
The before/after pair opening the readme takes the other route. Those two screens already exist as live click:run blocks in the tutorial, so the blocks maintain them instead of shooting them again: a :screenshot: option writes each image on every documentation build. That keeps the readme’s front page in step with the code.
Use the command when the CLI you want to picture has no live block, and the directive when it does.
Once committed, an image goes stale the first time the CLI’s help changes. tests/test_screenshots.py reads the SVG back, rebuilds the terminal text from the glyph coordinates, and compares it to what the command prints today. It fails on the first line that diverged, and re-running the command above refreshes the picture.
GitHub integration¶
A README can track the reader’s theme. Capture the same screen twice, once per chrome, with the CLI’s own theme moving along:
$ click-extra screenshot --output docs/assets/help-dark.svg -- my-cli --theme dark --help
$ click-extra screenshot --output docs/assets/help-light.svg --background light -- my-cli --theme light --help
Then hand both to a <picture> element, which GitHub renders in a README and which picks between them on prefers-color-scheme:
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/me/my-cli/main/docs/assets/help-dark.svg"/>
<img alt="my-cli help screen" src="https://raw.githubusercontent.com/me/my-cli/main/docs/assets/help-light.svg"/>
</picture>
The <img> is not a spare: every surface without the switch shows it, PyPI and most editors’ previews included. So it holds the capture that reads on the light background those surfaces default to. The <source> is the one a reader in dark mode gets instead.
Both URLs are absolute on purpose. A README is read on PyPI and in many forks of the page, and none of them resolve a repository-relative path. That is why every capture in this project’s own README is addressed through raw.githubusercontent.com.
Note
The switch keys on the browser’s color scheme, not on the theme toggle of a documentation site, so it belongs to a README rather than to these pages: Furo’s own switch would leave it unmoved.